【问题标题】:How do I stop UrlRewriter stripping my + symbols如何停止 UrlRewriter 剥离我的 + 符号
【发布时间】:2010-09-18 03:03:53
【问题描述】:

我在我的应用程序中使用了 Intelligencia 的 UrlRewriter,我遇到了一个问题,我设置的规则似乎正在从我的 url 中删除 + 符号。

例如,我想要网址 /category/catname/+tag+tag,但在我看来它是 /category/catname/ tag tag

有没有人有任何想法,这取决于我的正则表达式吗?我已经在调节器中尝试过,它匹配得很好。

<rewriter>
  <rewrite url="^/content/(.+)$" to="~/page.aspx?name=$1" />
  <rewrite url="^/category/(.+)$" to="~/catalog.aspx?category=$1" />
  <rewrite url="^/product/(.+)$" to="~/catalog.aspx?product=$1" />
  <rewrite url="~/login/" to="~/login.aspx"/>
</rewriter>

【问题讨论】:

    标签: c# asp.net regex urlrewriter


    【解决方案1】:

    这样做的原因是因为“+”在您的重写器实际得到它之前被网络服务器解析为空格。文字 + 是您不能在实际 URL 中使用的东西。如果您想使用 +,则需要将其引用为 %2B:“/category/catname/%2Btag1%2Btag2”。

    编辑:Here is an example of URL encoding 这说明了一些您​​不能使用的字符,以及如何对它们进行编码。如果您正在为 URL 寻找更具视觉吸引力的字符,您可以尝试“-”和“_”,它们都是有效的,我建议使用“-”。 url 的示例将是“/category/catname/-tag1-tag2”。

    【讨论】:

    • 感谢斯蒂芬的回答,我正在使用 - 来覆盖类别名称中的空格,所以我会考虑一下。但为答案欢呼。
    猜你喜欢
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    相关资源
    最近更新 更多