ARR reverse proxy outbound rewrite rule for redirections

arriis-7.5reverse-proxyrewrite

I'm currently trying to put together a proof of concept on mixing various technologies onto one web site in order to ease migrations and add flexibility.
The idea is to create one 'mashup' site behind an IIS 7.5 ARR reverse proxy.

For the time being the ARR reverse proxy forwards all request to our main site.
The request are as follow:

 client -> ARR: Get /
 ARR -> Server 1: Get /
 Server 1 -> ARR: 200: /index.htm
 ARR -> client: 200: /index.htm

…so far so good.

Let's say, I want to add a new site (root of another server) as a subsite of my main website.
a simple inbound rule does the trick:

<rule name="sub1" stopProcessing="true">
  <match url="^mySubsite(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
  <action type="Rewrite" url="http://server2/{R:1}" />
</rule>

The requests now are:

 client -> ARR: Get /mySubsite
 ARR -> Server 2: Get /
 Server 2 -> ARR: 200: /index.htm
 ARR -> client: 200: /index.htm

… still ok.

The issue comes when the site on server2 sends a redirection (e.g. to a login page). In the case of SharePoint, it will redirect the user to: /_layouts/Authenticate.aspx?Source=%2F
…which does not exists:

client -> ARR: Get /mySubsite
ARR -> Server 2: Get /
Server 2 -> ARR: 301: /_layouts/Authenticate.aspx?Source=%2F
ARR -> client: 301: /_layouts/Authenticate.aspx?Source=%2F
client -> ARR: Get /_layouts/Authenticate.aspx?Source=%2F
ARR -> client: 404: Not Found

Does anyone know a way write the outbound rule to rewrite the response from server 2 "301: /_layouts/Authenticate.aspx?Source=%2F" to "301: /mySubsite/_layouts/Authenticate.aspx?Source=%2FmySubsite%2F"?

Best Answer

I solved this by using subdomains. So instead of:

www.mydomain.com/mysite1
www.mydomain.com/mysite2

I'm using:

mysite1.mydomain.com
mysite2.mydomain.com

This means that all relative links and redirects still work as they did before.

If there really is a need to rewrite the location header, see this walkthrough