在url中使用连字符还是下划线是更好的惯例?
应该是/about_us还是/about-us?
从可用性的角度来看,我个人认为/about-us对最终用户来说要好得多,而谷歌和大多数其他网站(以及javascript框架)使用下划线命名模式。只是风格的问题吗?破折号有兼容性问题吗?
在url中使用连字符还是下划线是更好的惯例?
应该是/about_us还是/about-us?
从可用性的角度来看,我个人认为/about-us对最终用户来说要好得多,而谷歌和大多数其他网站(以及javascript框架)使用下划线命名模式。只是风格的问题吗?破折号有兼容性问题吗?
当前回答
就我个人而言,我会避免使用about-us或about_us,而使用about。
其他回答
一些较老的web主机和DNS服务器实际上在解析url的下划线时存在问题,所以这可能是这些约定的一部分。
谷歌过去没有将下划线作为单词分隔符,我认为这很疯狂,但现在显然有了。由于这段历史,破折号是首选。尽管从搜索引擎优化的角度来看,下划线现在是允许的,但我仍然认为破折号是最好的。
一个好处是,一般不懂电脑的上网用户更有可能在键盘上输入破折号,他们甚至可能不知道下划线是什么。
对于最终用户视图,我更喜欢“about-us”或“about us”,而不是“about_us”
I'm more comfortable with underscores. First of all, they match in with my regular programming experience of variable_names_are_not-subtraction, second of all, and I believe this was mentioned already, words can have hyphens, but they do not ever have underscores. To pick a really stupid example, "Nation-state country" is different from "nation state country". The former translates something like "the land of nation-states" (think "this here is gun country! Best move along, y'hear?"), whereas the latter looks like a list of sometime-synonyms. http://example.com/nation-state-country/ doesn't appear to mean the same as http://example.com/nation-state_country/, and yet, if hyphens are delimiters/"space"s in addition to characters in words, it can. The latter seems more clear as to the actual purpose, whereas the former looks more like that list, if anything.
更好的利用。- /作为分隔符,因为_似乎不是分隔符。
http://www.sistrix.com/blog/832-how-long-may-a-linktext-be.html