IIS Reverse Proxy with URL rewrite.

Hi all, hoping to leverage the wealth of knowledge contained here.
Any assistance would be very welcome.
I'm having an issue getting a reverse proxy and URL rewrite working in IIS 7.0.

I need to redirect all requests with a specific virtual directory suffix only.
ie; https://domain.test.com/outbound/Content/query_etc
With /Outbound/ being the trigger.
This should be redirected to http://10.10.10.10/inbound/Content/query_etc

While at the same time, requests without the /outbound/ suffix should be handled locally.

I have configured the reverse proxy as described in a few articles, and have had no luck.
Here's a snippet from my (sanitized) web.config at the site level.

<rewrite>
	<outboundRules>
		<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
			<match filterByTags="A" pattern="^http(s)?://10.10.10.10/inbound/(.*)" />
			<action type="Rewrite" value="https://domain.test.com/outbound/{R:2}" />
		</rule>
		<preConditions>
			<preCondition name="ResponseIsHtml1">
				<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
			</preCondition>
		</preConditions>
	</outboundRules>
		<rules>
			<rule name="ReverseProxyInboundRule1" stopProcessing="true">
				<match url="^outbound/(.*)" />
				<action type="Rewrite" url="http://10.10.10.10/inbound/{R:1}" appendQueryString="true" logRewrittenUrl="false" />
			</rule>
		</rules>
</rewrite>

To me, this looks correct, yet it doesn't work.
With this, I get the normal 404 - Error Code 0x80070002, with the text indicating the local directory doesn't exist, so.... not being picked up by the filter for redirection.

April 30th, 2015 3:21am

Hi Andrew,

This requires the following prerequisites:

  1. IIS 7 or above with ASP.NET role service enabled.
  2. URL Rewrite Module installed. For more information, see Using the URL Rewrite Module.

Hope you have running ASP role service installed on the server.

How about we break it apart and  start with a simple rewrite rule just to check if it works.

Create a simple rewrite rule that will rewrite URLs using the following format:

http://localhost/article/342/some-article-title
to:
http://localhost/article.aspx?id=342&title=some-article-title.

Once this is done skip the <outboundRules> and try with inbound rules only.

Once everything is working you can work on the complete rewrite.

References:

Creating Rewrite Rules for the URL Rewrite Module

Free Windows Admin Tool Kit Click here and download it now
April 30th, 2015 6:19am

Hi Andrew,

Looking at your requirements it appears you need Reverse Proxy To Another Site/Server.

By using URL Rewrite Module together with Application Request Routing module you can have IIS 7 act as a reverse proxy.

It seems like URL Rewrite can't re-route the request somewhere else out of the server.

Even when you rewrite the url the actual connection remains with the server. Hence if your original server doesn't have /inbound/Content/query_etc  it will fail with 404.

Hosting multiple domain names under a single account using URL Rewrite.
Its a common desire to have a single IIS website that handles multiple sites with different domain names.

References:

How to create a url alias using IIS URL Rewrite:

http://blogs.technet.com/b/mspfe/archive/2013/11/27/how-to-create-a-url-alias-using-iis-url-rewrite.aspx

Reverse Proxy with URL Rewrite v2 and Application Request Routing:

http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routi

April 30th, 2015 7:18am

Thanks for your response.

I have ASP.Net role service installed, as well as Application Request Routing and URL Rewrite modules installed.
To clarify, yes, I need to selectively reverse proxy to another external server, and URL rewrite.
Hosting both sites in the same IIS instance is not feasible.

I can create a URL rewrite for internal sites just fine, all is working.
I can also enable a Redirect function to successfully forward to the external URL, but only with wildcard URL pattern matching, ie; (.*)
And obviously, this shows the incorrect URL in the browser.

So, I'm still stuck on 2 points.
1 - Creating a URL pattern match to only effect the /Outbound/ queries, while ensuring the rest of the query is carried forward to the new address.
2 - Getting the /Outbound/ queries to be readdressed and forwarded to the external server.

In principal, similar to this....
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing


Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 12:32am

Hi Andrew,

Your point 1 is doable, essentially that is shown in the link for reverse proxy.

But point 2, I doubt, as reverse proxy would mean server1 would serve all the request though it for server2. You can't use URL Rewriting to do a DNS redirect. As what I have seen is its either full domain or nothing.

Sorry to say but this is not the correct forum as your question is specific to certain IIS feature.

You would get more response in the specialized link below:

http://forums.iis.net/1152.aspx/1?URL+Rewrite+Module

May 1st, 2015 3:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics