IIS 7 Reverse Proxy & HTTP 301 Redirects

iis-7redirectreverse-proxy

I'm trying to setup a reverse proxy for my website. Basically, I have an external site example.com/site/folder that needs to reverse proxy to some internal VMs. Here's a little background

  • All machines run Server 2008 (Standard)
  • 1 machine (the reverse proxy server.example.com) has an external IP
  • Several other internal VMs run IIS 7 and Server 2008

I've got the reverse proxy working and I can successfully send requests matching example.com/site/folder/ over to site-internal.example.com/folder/

However I'm having problems with 301 redirects that are returned by the internal VMs. When the user goes to http://example.com/site/folder without the trailing slash, the internal VM shoots back a redirect to go to folder/. This causes a 404 at the host machine level because example.com/folder/ does not exist.

On server.example.com I added the pre-configured URL rewrite rule to append the trailing slash for me — but when I enable this rule it seems to be too broad. Although it fixes the 404 errors and forces the client from folder to folder/ before it is proxied, the rule also adds a / to regular requests (ie. example.com/site/images/test.jpg becomes example.com/site/images/test.jpg/) This causes a 404 at the VM level because there is no file that matchines test.jpg/

Any thoughts on how to get around this? I'd prefer to make all changes at the host machine level (rather than the VMs) — but if I absolutely have to change the VMs I can do that.

Best Answer

I'm not sure what you're using for the reverse-proxy and whether it's just URL Rewrite by itself, but ARR is the way to do this. I've put together some videos on how to setup ARR as a reverse-proxy, and some tricks to consider. Check it out starting with week 31 here.

ARR will proxy all requests including subpages and subfolders. Then you can use URL Rewrite on the public (ARR) server to remove trailing slashes and such for search engine purposes.

Related Topic