【问题标题】:Url rewriting not working as expected网址重写未按预期工作
【发布时间】:2012-03-12 08:42:48
【问题描述】:
我正在尝试重写规则,以便如果 URL 中没有 .svc,它应该重写并在 URL 中附加 .svc。
这些是我的规则:
<rewrite>
<rules>
<rule name="RemoveSVC" stopProcessing="true">
<match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)$" />
<action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
谁能告诉我为什么这条规则不起作用?
【问题讨论】:
标签:
wcf
url-rewriting
iis-7.5
【解决方案1】:
我想你想要:
<rewrite>
<rules>
<rule name="RemoveSVC" stopProcessing="true">
<match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)" />
<action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
去掉末尾的$符号。
我还会删除 localhost/ 部分,因为这仅适用于您的本地开发 PC,当您部署到生产环境时,它将不再是 localhost:
<match url="RestApp/Services/([a-zA-Z0-9]*)/(.*)" />
<action type="Rewrite" url="RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />