iis7 url 将 webforms aspx 重写为 mvc 页面
iis7 url rewrite for webforms aspx to mvc page
我有一个 /contact.aspx
的网站,它成功重定向到 /contact
但我想将我的旧 /content.aspx?contentid=123
重定向到 /about/123
这是我 web.config:
中的重定向 XML 部分
<rewrite>
<rules>
<rule name="contact" patternSyntax="Wildcard" stopProcessing="true">
<match url="contact.aspx" />
<action type="Redirect" url="Contact" redirectType="Found" />
</rule>
<rule name="Content" patternSyntax="Wildcard" stopProcessing="true">
<match url="content.aspx?contentID=*" />
<action type="Redirect" url="About/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
访问 mydomain.com/content.aspx?contentid=123 给我一个 404。
也试过没有 appendQueryString="false"
对我来说似乎很容易修复,但我遗漏了一些东西...
使用正则表达式而不是通配符也会得到 404:
<rule name="Content">
<match url="content.aspx?contentID=([0-9]+)" />
<action type="Redirect" url="About/{R:1}" redirectType="Found" />
</rule>
来自IIS rewrite module configuration documentation.
The URL string that is evaluated against the pattern does not include the query string. To include the query string in the rule evaluation you can use the QUERY_STRING server variable in the rule’s condition.
所以在大量的 jiggery-pokery 测试之后,我认为这应该可行:
<rule name="Content" patternSyntax="ECMAScript" stopProcessing="true">
<match url="content.aspx" />
<conditions>
<add input="{QUERY_STRING}" pattern="contentID=([^&]+)" />
</conditions>
<action type="Redirect" url="About/{C:1}" redirectType="Found" appendQueryString="False" />
</rule>
我有一个 /contact.aspx
的网站,它成功重定向到 /contact
但我想将我的旧 /content.aspx?contentid=123
重定向到 /about/123
这是我 web.config:
<rewrite>
<rules>
<rule name="contact" patternSyntax="Wildcard" stopProcessing="true">
<match url="contact.aspx" />
<action type="Redirect" url="Contact" redirectType="Found" />
</rule>
<rule name="Content" patternSyntax="Wildcard" stopProcessing="true">
<match url="content.aspx?contentID=*" />
<action type="Redirect" url="About/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
访问 mydomain.com/content.aspx?contentid=123 给我一个 404。
也试过没有 appendQueryString="false"
对我来说似乎很容易修复,但我遗漏了一些东西...
使用正则表达式而不是通配符也会得到 404:
<rule name="Content">
<match url="content.aspx?contentID=([0-9]+)" />
<action type="Redirect" url="About/{R:1}" redirectType="Found" />
</rule>
来自IIS rewrite module configuration documentation.
The URL string that is evaluated against the pattern does not include the query string. To include the query string in the rule evaluation you can use the QUERY_STRING server variable in the rule’s condition.
所以在大量的 jiggery-pokery 测试之后,我认为这应该可行:
<rule name="Content" patternSyntax="ECMAScript" stopProcessing="true">
<match url="content.aspx" />
<conditions>
<add input="{QUERY_STRING}" pattern="contentID=([^&]+)" />
</conditions>
<action type="Redirect" url="About/{C:1}" redirectType="Found" appendQueryString="False" />
</rule>