IIS Rewrite not working (but redirecting does)

I tried to play with re-writing URLs using the Rewrite 2.0 module, but I was not lucky that it works. What I'm trying to do is rewrite all the calls in the web application on port 80 to other applications hosted on IIS (or possibly on different servers on the network). Using the GUI provided by IIS, I created the following rule:

<rewrite> <rules> <rule name="ReverseProxyInboundRule1" stopProcessing="true"> <match url="site1/(.*)" /> <action type="Rewrite" url="http://localhost:7001/{R:1}" /> </rule> </rules> </rewrite> 

Quiet, but unfortunately it does not work. On the other hand, when I change the type of action to Redirect , it works fine.

What could be the problem?

+8
url-rewriting iis url-rewrite-module
source share
4 answers

I came across this question yesterday, and it took me a long time to understand.

The key here is that you have the http:// prefix in your action rewrite; making this a special case that needs to be handled by routing application requests. The first step is to make sure that the application request routing module is installed. The module can be found at https://www.iis.net/downloads/microsoft/application-request-routing . Once it is installed, go to the IIS web server (level from your website) and open the application request caching function. From the actions on the right, select Server.Proxy.Settings and make sure that the Enable proxy box is checked. This allows you to redirect the task of rewriting URLs to Application Request Routing, and your reverse proxy should work for external requests.

The idea came from this excellent blog post since 2009: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

+20
source share

Stumbled upon this old post when I was trying to solve the same problem.

SOLVE!

Using the Reuse URL Function in IIS Manager I created a friendly URL rule.

This worked fine, and when I looked at the rule in the web.config (www root) file, it showed 1 rule for redirection and 1 rule for rewriting.

I edited it for 1 match. Then I simply duplicated this code, editing the product identifier for each. Example below:

  <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^product\.php$" /> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern="^id_product=\b35\b" /> </conditions> <action type="Redirect" url="990mm-bohemia-cast-iron-electric-radiator" appendQueryString="false" /> </rule> 

The first rule looks for the string "product.php" in the URL and "id_product=35" , then redirects to "990mm-bohemia-cast-iron-electric-radiator" , which does not currently exist. Then (see below)

  <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> <match url="^\b990mm-bohemia-cast-iron-electric-radiator\b" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="product.php?id_product=35" /> </rule> 

This rule overwrites the "product.php?id_product=35" bit with "990mm-bohemia-cast-iron-electric-radiator", creating a new redirection location.

+3
source share

Change the rewrite URL to AbsolutePath instead of http: // ... it should be

This worked for me, but in my case I was texting to a fixed web page.

0
source share

I had a 404 error with URL rewriting. Maybe you can find it. Please check it https://stackoverflow.com>.

0
source share

All Articles