Using IIS 7.5 and the URL Rewrite 2.0 module, I want to rewrite the relative path "/myapp" to "/myapp-public", without a browser redirection.
I placed the following web.config file in wwwroot:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to public" stopProcessing="true">
<match url="^myapp" />
<action type="Rewrite" url="/myapp-public" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Instead of rewriting the URL on the server side, IIS responds with a "301 Moved Permanently" which redirects the user to "/myapp-public". It is behaving as if I had used an action of type "Redirect" instead of "Rewrite".
Does anyone know why a "Rewrite" action would perform a redirect instead? Any thoughts on how to debug this issue further? Thanks!
Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.
A rewrite is a server-side operation that occurs before a web server has fully processed a request. A rewrite is not visible to website visitors, since the URL displayed in the browser does not change.
Checking if the URL Rewrite module is installed To see if the URL Rewrite module is installed, open IIS Manager and look in the IIS group - if the module is installed, an icon named URL Rewrite will be present. The screenshot below shows an example of a server when the module is installed.
You are running into the courtesy folder redirect that IIS does for you, see here: http://support.microsoft.com/kb/298408/EN-US. To get around this, add the trailing slash to your rewrite url, like so:
<action type="Rewrite" url="/myapp-public/" />
But you have another issue too if these are in fact your actual urls. Your match url will match on your rewrite url and will cause an infinite loop, since ^myapp matches myapp-public. You can add the end of string ($) to your match url to fix this, i.e. ^myapp$ to prevent myapp-public from matching on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With