Don
Don

Reputation: 1572

IIS 7.5 Rewrite URL with Reverse Proxy from a default web site to two web sites failed

I want the users to access my intranet test website - http://mywebsite:9090 if they type http://mywebsite/test.

I am following section - 7. Reverse Proxy To Another Site/Server in http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx to create a url rewrite.

After checked the “Enable proxy” checkbox located in Application Request Routing feature view in IIS Manager. I have the rule as -

<rule name="Proxy">
  <match url="(.*/test)" />
  <action type="Rewrite" url="http://{HTTP_HOST}:9090/{R:1}" />
</rule>

However this does not work. It does not direct me to http://mywebsite:9090 but prints out that http://mywebsite/test is not found.

Changed the rule to see if it is a proxy problem by using -

<rule name="Proxy">
  <match url="(.*)" />
  <action type="Rewrite" url="http://{HTTP_HOST}:9090/{R:1}" />
</rule>

I can see it can direct me to http://mywebsite:9090 when I browse http://mywebsite.

What happens to my first rule?

Thanks for the help.

Upvotes: 4

Views: 5627

Answers (1)

brettbaggott
brettbaggott

Reputation: 300

What you want is the rule:

"^test(/.*)?$"

Your action can stay the same.

With the rule above, you're saying "if the first thing after the HTTP_HOST part of the url (which includes the first slash, i.e. "http://mywebsite.com/") is equal to test, then you create a capture group on all of the rest of the URL (if there is any), rewrite the URL to have the HTTP_HOST, add the port 9090, and then append whatever was in the first capture group (i.e. R:1, whatever is in the parens in the regex).

Make sure you uncheck Append query string as you are capturing what you need as part of the Regex and don't need that.

Credit where's it due, I was struggling with solving this too and found what I needed here:

http://forums.iis.net/t/1180781.aspx

Upvotes: 6

Related Questions