如何阻止 UrlRewriter 剥离我的 + 符号
我在我的应用程序中使用 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>
I'm using Intelligencia's UrlRewriter in my application and I'm having a problem where the rules I've setup appear to be stripping the + symbol from my url.
For example I want to have the urls /category/catname/+tag+tag
but it appears to me as /category/catname/ tag tag
Does anyone have any ideas and is this down to my regular expression? I've tried it in regulator and it matches fine.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它这样做的原因是因为“+”在重写器实际获取之前就被网络服务器解析为空格。 文字 + 是不能在实际 URL 中使用的内容。 如果您想使用+,那么您需要将其引用为%2B:“/category/catname/%2Btag1%2Btag2”。
编辑: 这是 URL 编码的示例 这说明了一些您不能使用的字符使用以及如何对它们进行编码。 如果您正在为 URL 寻找更具视觉吸引力的字符,您可以尝试使用“-”和“_”,它们都是有效的,我建议使用“-”。 url 的示例为“/category/catname/-tag1-tag2”。
The reason why it is doing that, is because the "+" gets parsed as a space by the webserver before your rewriter actually get it. A litteral + is something that you can not use in an actual URL. If you want to use a + then you need to reference it as something like %2B: "/category/catname/%2Btag1%2Btag2".
Edit: Here is an example of URL encoding This illustrates a few of the characters you can not use, and how to encode them. If you are looking for more visual appealing characters for a URL, you can try "-" and "_" which are both valid, I'd suggest the "-". an example of the url would then be "/category/catname/-tag1-tag2".