访问带有空格后跟斜杠的 url 时出现问题
当我尝试访问带有空格后跟斜杠的产品时,我的网站出现问题。它不起作用。仅在文章中使用空格效果很好,但当空格后跟斜杠时则不起作用。有什么想法吗?难道是IIS:en不知道如何路由?还是浏览器将空格、斜杠视为符号?
示例:
文章编号:VT xxx / xx 不起作用。
文章编号:VT xxx/xx 有效。
我也不能直接去掉空格,因为其他产品的商品编号中已经包含了这些空格。
我尝试访问的网址将是这样的。
somestore.com/product/VT XXX / XX/
<- 不起作用。
somestore.com/product/VT XXX/XX/
<- 有效。
只有当空格后跟斜杠时,它才找不到我的产品。
I have a problem on my website when i am trying to access a product with a space followed by a slash. It does not work. Just using a space in a articleno works fine, but when the space is followed by a slash it does not work. Any ideas to why this is? Is it the IIS:en not knowing how to route? Or is it the browser treating space, slash as a sign?
Example:
ArticleNo: VT xxx / xx does not work.
ArticleNo: VT xxx/xx works.
I can't just strip the spaces either because other products have got them in their articlenumbers.
The url i am trying to access will be like this.
somestore.com/product/VT XXX / XX/
<- Does not work.
somestore.com/product/VT XXX/XX/
<- Does work.
It is only when space is followed by the slash that it does not find my product.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑是网络服务器没有处理这个问题,而不是浏览器。您收到什么错误消息?
网址中的正斜杠表示子目录,因此在您的示例中,网络服务器会将
VT xxx/xx
解释为VT xxx
中的xx
文件> 目录。斜杠前面有空格会使服务器感到困惑,因为目录名称末尾不允许有空格。如果正斜杠是产品 ID 的一部分,则需要对 url 中的空格和斜杠进行编码,并在服务器上进行处理。
I suspect it is the webserver that is not handling this, rather than the browser. What error message are you getting?
A forward slash in a url indicates a subdirectory so in your example, the webserver will interpret
VT xxx/xx
as thexx
file in theVT xxx
directory. Having a space precede a slash will confuse the server because a space at the end of a directory name is not allowed.If the forward slash is part of the product id, you will need to encode the space and the slash in the url and handle that on the server.
如果产品代码确实包含空格,则对链接进行 url 编码。空格的代码是
%20
If the the product code really contain spaces then url encode you links. The code for space is
%20