Forum Moderators: open

Message Too Old, No Replies

ASP and rewriting 301 redirects across a site?

Brand new to ASP, is there a way to do that?

         

bobosse

6:57 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



Hello,

I am dealing with an issue I would need assistance with. I have been programming in PHP for several years, learnt to implement URL rewriting through the htaccess file, etc...

I am working on a project, ASP related, which I am not that familiar with...unfortunately.

The site has thousands of pages, category, supplier, product pages, and they currently use some URL rewriting (Aspi i believe). Well, we have some issues the way the URLs are structured and would like to introduce a new format. In order to do that, we'll need to 301 redirect all the old URLs to the new format, and I am not sure how to proceed in ASP.

I believe the htaccess file is unique to Apache, so which file do you modify for URL rewriting with ASP?

Also, would you guys mind looking at the URL format and give me your feedback on the proper URL rewrite commands to do the 301 redirects across the site? Any good resource I could refer to as well?

Thanks! Bobosse

pageoneresults

7:18 pm on Dec 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello bobosse. If they are using ISAPI_Rewrite, you can do everything you need to do from the root level httpd file.

Here are some basic examples...

Redirect Primary Domain to Sub-Domain

RewriteCond Host: ^example\.com
RewriteRule (.*) http\://www\.example\.com$1 [I,RP]

Redirect Old Page to New Page

RewriteRule /old-file.asp http://www.example.com/new-file.asp [I,O,RP,L]

If you are familiar with regular expressions on Apache, I do believe working with the rewrite routine (httpd.ini) for IIS is basically the same.

Others with more technical experience in this area will most likely chime in.

bobosse

7:52 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



That's great, thanks a bunch - looks like it's close from the htaccess file config.

I guess the main issue I have is the following.

We want to modify the current URL format they use and introduce a "tree" format, kind of more logical than what they use.

Current URLs are like that:
[mydomain.com...]

The 1000 is the category ID.

What we want to do is:
[mydomain.com...]

But, the problem is that the category name is not is the URL currently, so it ain't easy.

What would be the best to do that? I mean writing the URL rewriting the asp pages to htm pages should not be too difficult, but what about setting up 301 permanent redirects without having the category name...

Any tricks you guys could think of?
B.

Small Website Guy

7:06 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



Put something like the following in the Application_BeginRequest method in the Global.asax file, changing the urls as appropriate:

if (Request.Url.AbsoluteUri.ToLower().StartsWith("http://old"))
{
Response.StatusCode = 301;
Response.StatusDescription = "Moved Permanently";
Response.RedirectLocation = "http://new";
Response.End();
}