Reputation: 2081
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!
Upvotes: 8
Views: 3287
Reputation: 1569
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.
Upvotes: 14