ASP.NET / IIS7 Url Rewrite maps not working

天大地大妈咪最大 提交于 2019-12-05 11:05:36

This article http://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module and code below worked for me.

<rewrite>
    <rules>
        <rule name="Redirect rule1 for RedirectURLs">
            <match url=".*" />
            <conditions>
                <add input="{RedirectURLs:{REQUEST_URI}}" pattern="(.+)" />
            </conditions>
            <action type="Redirect" url="{C:1}" appendQueryString="false" />
        </rule>
    </rules>
    <rewriteMaps>
        <rewriteMap name="RedirectURLs">
            <add key="/privacy.php" value="/privacy" />
        </rewriteMap>
    </rewriteMaps>
</rewrite>

I was having a similar problem and found this question. It took me a little while, but I was able to figure out what the problem was.

My rewriteMap contained the urls "/Default2.aspx" and "/Dashboard.aspx".

When I would go to Default2.aspx, I would get a 404 rather than get redirected to Dashboard.aspx as expected.

The issue I found was that on my machine, the application was running in a subdirectory. The rewriteMap paths would only work if I used the full path (including the application folder), e.g., "/TestSite/Default2.aspx".

So I could have added duplicate entries in my rewriteMap to account for application directories on developer machines, but that seemed messy. I looked at the other rewrite rules in the application that did not have this issue and I noticed that they were using the {REQUEST_FILENAME} variable, rather than {REQUEST_URI}. So I switched the rule to use {REQUEST_FILENAME} and remove the first slash from the urls in my rewriteMap.

Do you have Url rewriting installed as part of IIS7/7.5? This is not installed by default. Also, make sure your app pool is set to integrated pipline mode, no classic.

Edit

From this:

http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/

This only thing I see that you're doing is adding the 'stopProcessing' attribute. Have you tried removing that?

Wigid

Previously I had same problem as you described.

Could you update your code to

<match url="(.*)" />

and I hope you aware,

 <add input="{Information:{REQUEST_URI}}" pattern="(.+)" />

this condition will capture full URL except the domain. example on this url: www.example.com/Information/CorporateSales.aspx it will check matching condition of Information/CorporateSales.aspx on rewriteMap

and for sure it wont be match with this url

www.example.com/old/Information/CorporateSales.aspx

Did you reset the app pool and the iis site ?

In some cases it can take up to 72 hours (iirc) to propagate throughout the world.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!