是否有任何技术原因需要将网址上的空格替换为破折号?
我想知道使用破折号(或任何其他允许的字符)是否只是因为空格编码(%20)使网址不太清晰。我没有看到任何技术原因,但可能有一些我不记得或不知道的事情。
I wanted to know if using dashes (or any other allowed character) is just because the whitespace encoding (%20) make urls less legible. I don't see any technical reason for this, but there might be something that I don't remember or don't know about.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这主要是由于用户的偏好。只要所有组件正确处理编码,就不会产生技术差异。
这是一篇有趣的文章: http:// /www.codinghorror.com/blog/2006/04/of-spaces-underscores-and-dashes.html
不过,他关于更喜欢破折号而不是下划线的观点是有效的,因为大多数搜索引擎将破折号视为断词符,但下划线则不然,因此它被视为单个单词。因此,这是使用破折号而不是下划线来替换空格的有效技术原因...但据我所知,没有技术要求在 URL 本身的空格上使用破折号。
I believe that it's primarily due to user preference. As long as all the components handle the encoding properly, it should make no technical difference.
Here is an interesting writeup on it: http://www.codinghorror.com/blog/2006/04/of-spaces-underscores-and-dashes.html
His point about preferring a dash over an underscore is valid though, as most search engines treat a dash as a word-breaker, but an underscore is not so it's treated as a single word. Therefore, that is a valid technical reason for a dash to be used instead of an underscore to replace spaces... but there's no technical requirement that I know of to use dashes over spaces in the URL itself.
破折号可能已用于其他用途,例如带有破折号的文件名,因此将它们用于空格可能会导致混乱,具体取决于它们的使用方式。
%20
是 ASCII 字符 32 的十六进制等效值,它是一个空格。SO 使用破折号使 URL 变得“友好”,但这不是必需的。
根据 W3c 规范:
Dashes may already be used for something else, such as a filename with dashes so using them for a space could cause confusion, depending on how they're used.
%20
is the hexadecimal equivalent of the ASCII character 32, which is a space.SO uses dashes to make URLS "friendy" but it is not a requirement.
According to the W3c Spec: