IIS URL redirect redirected

goal

Using IIS 7.5 and the URL module Rewrite 2.0, I want to rewrite the relative path "/ myapp" to "/ myapp-public" without redirecting the browser.

What i tried

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> 

Problem

Instead of rewriting the server-side URL, IIS responds with β€œ301 Moved Permanentently,” which redirects the user to β€œ/ myapp-public”. It behaves as if I used an action such as "Redirection" instead of "Overwrite".

Does anyone know why the Rewrite action will perform a redirect? Any thoughts on how to debug this question further? Thanks!

+5
source share
1 answer

You go to the correspondence folder that IIS does for you, see here: http://support.microsoft.com/kb/298408/EN-US . To get around this, add a trailing slash to your rewritten url, for example:

 <action type="Rewrite" url="/myapp-public/" /> 

But you have another problem if they are actually your valid addresses. Your match url will match your rewrite url and will cause an infinite loop since ^ myapp matches myapp-public. You can add the end of the line ($) to your match url to fix this, i.e. ^ Myapp $ to prevent myapp-public matching.

+7
source

Source: https://habr.com/ru/post/1208089/


All Articles