【发布时间】:2023-03-11 03:49:01
【问题描述】:
当 URL 包含特殊字符时,我的重写规则出现错误:
此网址http://www.example.com/bungalow/rent/state/texas/street/exloër/exloër 使用此重写规则:
<rule name="rentals by proptype+state+city+street">
<match url="^([a-zA-Z0-9-+]+)/rent/state/([a-zA-Z-+]+)/street/([a-zA-Zë-+]+)/([0-9a-zA-Zë-+']+)$" />
<action type="Rewrite" url="search_new.aspx?proptype={R:1}&state={R:2}&city={R:3}&street={R:4}" />
</rule>
导致 500 错误
此网址http://www.example.com/bungalow/rent/state/texas/street/exloër/exloër 使用此重写规则:
<rule name="rentals by proptype+state+city+street">
<match url="^([a-zA-Z0-9-+]+)/rent/state/([a-zA-Z-+]+)/street/([a-zA-Z-+]+)/([0-9a-zA-Z-+']+)$" />
<action type="Rewrite" url="search_new.aspx?proptype={R:1}&state={R:2}&city={R:3}&street={R:4}" />
</rule>
导致 404 错误
如何处理重写规则中的特殊字符?
更新 1
有问题的 URL 以 ë 字符显示,但是当我复制地址时,它被转义为 %c3%abr
使用此规则,我仍然会收到 404 错误:
<rule name="rentals by proptype+state+city+street">
<match url="^([a-zA-Z0-9-+]+)/rent/state/([a-zA-Z-+]+)/street/([a-zA-Z%-+]+)/([0-9a-zA-Z%-+']+)$" />
<action type="Rewrite" url="search_new.aspx?proptype={R:1}&state={R:2}&city={R:3}&street={R:4}" />
</rule>
所以我想真正的问题是,如何处理重写规则中的% 字符?
【问题讨论】:
-
你没有。 URL 中不允许使用这些内容。您必须先将它们转义,然后才能将它们变成 url。
-
@VDWWD 谢谢。我确实在使用那个模块。但是在阅读该页面后,我仍然无法解释为什么我的链接不起作用并引发错误。你能解释一下吗?
标签: asp.net url-rewriting web-config special-characters