views:

170

answers:

1

Hi all,

I've been experiementing with URL rewriting in IIS 6 and 7. On IIS 6, I've been using ISAPI Rewrite 3 and am trying to map URLs for one subdomain to another e.g.

http://subdomain1.domain.com/*

would be mapped to:

http://subdomain2.domain.com/*

I've tried to achieve this using:

RewriteEngine on

RewriteCond Host: subdomain1.domain.com RewriteRule (.*) subdomain2.domain.com/$1

but nothing seems to happen or show up in the IIS log or rewrite.log. I must be missing somethin to enable logging here - any ideas? Also, if anyone could suggest why my rules don't seem to be working it would be much appreciated.

One further question (sorry!) - was wondering on IIS 7 using the rewrite module, I can use the rewrite rules to redirect to content hosted on another instance of IIS (on a different server machine) but can't use the rewrite action to simply mask the URL - is this possible? At the moment, I'm just getting a 403 - forbidden error.

Many thanks for your help.

A: 

With regards to your second question about rewriting on IIS 7, you can use the Application Request Routing module to set up a reverse proxy between 2 servers so that content requested from the first server is seamlessly served from the second server.

http://learn.iis.net/page.aspx/489/using-the-application-request-routing-module/

JonNeale
Thanks for the information - any ideas whether this would work if one of the servers is IIS7 and the other IIS6? My initial impression is that this wouldn't be the case.
rwbutler
It should work. We've currently got an IIS 7 server reverse proxying a linux/nginx server. Basically, all that is happening is the page request is routed through from the IIS 7 server to the proxied server, and then the response is routed back the other way.
JonNeale
That's great thanks. I've managed to get the ARR module working so that requests to http://subdomain1.domain.com/* (served by the IIS 7 server) are translated to http://subdomain2.domain.com/* (served by the IIS 6 server). The major problem here however is that the IIS 6 server needs to be configured with outbound rules now as described in "Configuring rules for response rewriting" http://learn.iis.net/page.aspx/659/reverse-proxy-with-url-rewrite-v2-and-application-request-routing/ This brings me back to my original problem with ISAPI rewrite :(
rwbutler
Can you verify that requests are making it to the IIS 6 server? You could set up a redirect rule, and make sure redirects are happening, then try rewriting if that works. One of our old production redirect rules looked like this:RewriteCond %{HTTP:Host} ^somedomain.com$RewriteRule (.*) http\://someotherdomain$1 [NC,R=301]Maybe you could use it as a template
JonNeale
That also works thanks - just to summarise where I've got to so far:With IIS7 I can proxy traffic (using an inbound rule) from server 1 (IIS7) -> server2 (IIS6) and the URL is rewritten which is great. I get the page back from the IIS 6 server just fine. The only problem with this method is that because there is no outbound rule on the IIS6 server, links aren't translated meaning that as soon as I click one of links on this page, the original URL shows up in the browser URL bar which is the thing I've been trying to avoid by using URL rewriting.
rwbutler
Using the rules above with IIS6 and ISAPI rewrite I can redirect traffic from the first subdomain to the second. The major problem with this is that with these rules seem to result in the server returning the 'Moved Permanently' status code. This means that a redirect is performed and the true URL is displayed (i.e. subdomain2 rather than subdomain1). I was attempting to avoid this by using URL rewriting.Thanks again for all assistance so far - it's much appreciated.
rwbutler
One further detail I forgot to mention - I've left the [NC,R=301] bit off my rewrite rules in order to use the rewrite method rather than redirecting however a redirect still seems to be performed - might there be a parameter which forces the rewrite action rather than redirect?
rwbutler
And here are my redirect rules:RewriteCond %{HTTP:Host} ^subdomain1.domain.com$ RewriteRule (.*) http\://subdomain2.domain.com$1
rwbutler
Just wanted to let you know that I've now managed to resolve this issue now and thought I'd post the information here in case anyone else needs to do something similar.Basically the way I got this to work in the end was by using ARR and URL Rewrite module in IIS 7 to route the request the IIS 6 server where the content lives and then apply an outbound rule when the content is returned to the IIS 7 server which rewrites the page links.
rwbutler
I gave up on the ISAPI Rewrite approach as it seemed to be performing redirects (was returning the HTTP 302 - Resource Moved Permanently status code) rather than rewriting the URL in the browser address bar.
rwbutler