How to do 301 redirects in asp.net from old Apache mod_rewrite style urls when moving a site from php to asp.net?

StackOverflow https://stackoverflow.com/questions/362472

Question

I have an existing site in php running on Apache using the mod_rewrite plug-in. In other words, I currently have urls like www.example.com/section/subsection/ which Google and others have indexed.

However, the site needs a major upgrade, and I would like to move it to asp.net. I only have the option of using a shared hosting solution (iis 6, aps.net 3.5, full trust). So my question: How do I make asp.net do a 301 redirect from my old urls like www.example.com/section/subsection/ to their equivalent ones on the new asp.net site?

I obviously needs this to not loose the current rankings in the search engines.

Thanks, Egil.

Was it helpful?

Solution 3

According to Steve Sanderson’s blog post Deploying ASP.NET MVC to IIS 6 it do not look like there is an option to do url rewriting/redirection with IIS6 in a shared hosting set up, where you cant manually configure IIS. Gah...

OTHER TIPS

If you use the ASP.NET MVC framework it has a URL rewriting system built into it.

You can manually add 301 redirects into IIS using IIS Manager if you want to set up "moved" locations.

If you want to do URL re-writing then you will need to implement IHttpModule, hook up the BeginRequest event, and add that new class to the httpModules section in Web.config.

Okay...so this may be overkill and could possibly be done another way in two lines..BUT...

If you are keeping the same domain name then what I've done in the past is keep a table of old urls and how they map to new urls. On the application's request, I'll scan the table, if an old url is found then I'll add a header that does a 301 redirect to the new URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top