Search code examples
.htaccessasp.net-4.0http-status-code-301isapi-rewrite

ISAPI_Rewrite to 301 redirect old domain to new domain, running ASP.NET4


I have two identical websites on different URLs:

http://www.oldsite.co.uk and http://www.newsite.co.uk. I want to 301 redirect all requests from the old site to the new site for every kind of extension (e.g. 'index.htm', 'images/image.jpg', 'directory/subdirectory/' etc). All references to any kind of file/document/path on the old domain need to be directed to the same place on the new domain.

The sites run a content management system which uses .NET4.

I've tried this two ways so far: Firstly by setting up a permanent redirect in IIS. This works to an extent but gives me a new URL like this:

http://www.newsite.co.ukeurl.axd/5e42bf571e13754bbed8710d 2d377a5d/

All I've been able to find out with regards to the 'eurl.axd' stuff is that it's caused by the ASP.NET4 framework which is intercepting the request somehow during the redirect. The only solutions I've found would involve disabling asp.net 4 (which isn't an option as the CMS runs on this) or doing some kind of registry hack, which I really don't want to do (bearing in mind there are other domains on this server).

The other option is using ISAPI_Rewrite. I've tried this:

RewriteRule (.+) http://www.newsite.co.uk$1 [R=301,L] 

But that too gives the same issue with the eurl.axd stuff. So I tried this, which removes the eurl.axd stuff, but only seems to work for the homepage of the site - none of the other pages or resources:

RewriteRule (.*)eurl.axd/.* http://www.newsite.co.uk/$1 [R=301,L]

When I run this there's nothing in the error log but the rewrite log shows that the rule isn't working as desired, e.g. trying to access 'http://www.oldsite.co.uk/technical.aspx' just loads that page in the browser (no redirect) and outputs this log:

(2) init rewrite engine with requested uri /technical.aspx 
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf 
(1) Htaccess process request c:\inetpub\vhosts\oldsite.co.uk\httpdocs\.htaccess 
(3) applying pattern '(.*)eurl.axd/.*' to uri 'technical.aspx'

Does anyone know how to modify this rule such that it redirects all resources from old to new domain?

Many thanks!


Solution

  • Thanks folks. The way I ended up resolving this was by deleting all files from the old domain and removing any dependencies on it to ASP.NET4 (changing application pool to one which doesn't use .NET4 etc) then just setting up the simple permanent redirect in IIS. So I didn't end up using ISAPI_Rewrite at all - IIS handled it fine.

    So now, anything at my old domain points to the new domain, which is perfect.

    Thanks for your pointers folks, it's been interesting to look further into IIS, which I don't do very often.