ASP.NET / IIS7 Url Rewrite maps not working

2019-05-01 19:09发布

I've followed the instructions Learn IIS's webpage for adding static redirects with a rewrite map for my asp.net application.

The following is the config:

<rule name="Redirect rule1 for Information" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{Information:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    <action type="Rewrite" url="{C:1}" appendQueryString="true" />
</rule>

And

<rewriteMaps>
    <rewriteMap name="Information">
        <add key="/Information/CorporateSales.aspx"
             value="/KB/Information/CorporateSales" />
        <add key="/Information/ComputerRepair.aspx"
             value="/KB/Information/ComputerRepair" />
    </rewriteMap>
</rewriteMaps>

This was even originally created by the wizard in IIS's manager for using rewrite maps.

So the idea is that /Information/CorporateSales.aspx --> /KB/Information/CorporateSales with a 301 redirect (MOVED PERMANENTLY).

However I'm just getting the original aspx page (Which we're removing later) loading. I've even deleted the file incase it was defaulting to an existing resource, and with that i just get a plain 404 without the redirect.

Anyone have an idea?

Let me clarify something:

Rewrite module works, it's installed and running. My standard regex rules work nicely. But my rewrite map does not.

5条回答
相关推荐>>
2楼-- · 2019-05-01 19:33

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

查看更多
混吃等死
3楼-- · 2019-05-01 19:34

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>
查看更多
做个烂人
4楼-- · 2019-05-01 19:35

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?

查看更多
淡お忘
5楼-- · 2019-05-01 19:42

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.

查看更多
Summer. ? 凉城
6楼-- · 2019-05-01 19:55

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.

查看更多
登录 后发表回答