我想要这个URL
http://alpha.Mysite.io/Car/Details/{4f2a95ed-3582-4486-8ef6-8a8e6731161f}
重定向到
http://alpha.Mysite.io/Car/index.htm?Action=Details&guid={4f2a95ed-3582-4486-8ef6-8a8e6731161f}
GUID参数({4f2a95ed-3582-4486-8ef6-8a8e6731161f})每次都不同,因此需要传递给重定向的URL。
我使用ReWriteMap实现了基本的重定向,但是一旦我添加了无名的GUID参数,我就得到了一个404
这是来自webconfig的我的部分
<rewrite>
<rules>
<rule name="Rewrite rule1 for carAPI">
<match url=".*" />
<conditions>
<add input="{carAPI:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="true" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="carAPI">
<add key="/car/details/" value="/car/index.asp?Action=Details" />
</rewriteMap>
</rewriteMaps>
</rewrite>发布于 2018-01-25 01:05:49
在您的例子中,您不需要重写map。你可以用一条规则来完成所有的事情:
<rule name="Rewrite rule1 for carAPI" enabled="true" stopProcessing="true">
<match url="^Car/Details/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})" />
<action type="Rewrite" url="/Car/index.htm?Action=Details&guid={R:1}" appendQueryString="false" />
</rule>此规则将匹配Car/Details/{any valid .net guid}等urls并将其重写为Car/index.htm?Action=Details&guid={guid}
https://stackoverflow.com/questions/48426288
复制相似问题