Is '|' a recommended separator for semantic URLs?

*爱你&永不变心* 提交于 2019-12-10 09:16:26

问题


After researching Google and SO, there seems to be conflicting opinions on this.

We have run-in to a problem with Google Chrome substituting | separator as %7C, whereas Firefox and Safari do not.

Here's an example:

http://www.example.com/page1|sub-page2|sub-page-3

Are there any strict rules to follow when choosing a separator character for semantic URLs and are there any strong arguments against (or workarounds when) using |?


回答1:


| is not a valid character in a URL. Modern browsers will silently encode it to %7C when sending, and may or may not display this change in the address bar. Similarly, servers will silently decode the character for you.

This would have been a problem in last millennium, where browsers would crash just because you didn't specify http://, but today you can just use whatever you want and the browser will take care of it. However, automatic parsers such as http://example.com/test|fish Markdown may not agree to it being a valid URL. In this case, it looks like it does, but try that on my forums and it will complain at you.




回答2:


Internet explorer/chrome use url encoding when displaying the url in the address bar after a page request has been made, %7C is the safe way of displaying a pipe ('|') so its not a problem that chrome is doing this.

as a cheeky fix to make all browsers behave the same way, why not use %7C as your separator from the get-go, instead of a pipe, and then all browsers should interpret this as a pipe for you behind the scenes, but display it as &7C in the address bar.



来源:https://stackoverflow.com/questions/22790773/is-a-recommended-separator-for-semantic-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!