Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(18)
更好地使用。 - / 作为分隔符,因为 _ 似乎不是分隔符。
http://www.sistrix.com/blog /832-how-long-may-a-linktext-be.html
Better use . - / as separators, because _ seems not to be a separator.
http://www.sistrix.com/blog/832-how-long-may-a-linktext-be.html
URL 中允许有空格,因此您可以在链接中使用“/about us”(尽管这将被编码为“/about%20us”。但说实话,这始终是个人偏好,因此没有真正的答案 我会
遵循破折号可以出现在单词中的约定,因此空格应该转换为下划线。
Spaces are allowed in URL's, so you can just use "/about us" in a link (although that will be encoded to "/about%20us". But be honest, this will always be personal preference, so there is no real answer to be given here.
I would go with the convention that dashes can appear in words, so spaces should be converted to underscores.
杰夫对此有一些想法:https://blog.codinghorror.com/ of-spaces-underscores-and-dashes/
两者都有缺点。 我建议你选择一个并保持一致。
Jeff has some thoughts on this: https://blog.codinghorror.com/of-spaces-underscores-and-dashes/
There are drawbacks to both. I would suggest that you pick one and be consistent.
我更喜欢使用下划线。 首先,它们符合我的常规编程经验
variable_names_are_not-subtraction
,其次,我相信已经提到过,单词可以有连字符,但它们没有下划线。 举一个非常愚蠢的例子,“民族国家”与“民族国家”不同。 前者翻译为“民族国家的土地”(想想“这里是枪支国家!最好继续前进,你听到了吗?”),而后者看起来像是一个有时同义词的列表。http://example.com/nation-state-country/
似乎与http://example.com/nation-state_country/
含义不同,然而,如果连字符除了单词中的字符之外也是分隔符/“空格”,则可以。 后者似乎更清楚实际目的,而前者看起来更像该列表(如果有的话)。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 ashttp://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.SEO 大师 Jim Westergren 对此进行了测试 2005 年,从严格的 SEO 角度来看,得出的结论是 +(加号)实际上是最好的单词分隔符。 然而,这似乎不合理,可能是由于搜索引擎算法中的错误所致。 他建议 -(破折号)以提高可读性和 SEO。
The SEO guru Jim Westergren tested this back in 2005 from a strict SEO perspective and came to the conclusion that + (plus) was actually the best word delimiter. However, this doesn't seem reasonable and may be due to a bug in the search engines' algorithms. He recommends - (dash) for both readability and SEO.
下划线替换不允许空格的空格。 破折号(连字符)可以是单词的一部分,因此用连字符连接已经包含连字符的单词是丑陋/令人困惑的。
坏:
好:
Underscores replace spaces where whitespace is not allowed. Dashes (hyphens) can be part of a word, thus joining words with hyphens that already include hyphens is ugly/confusing.
Bad:
Good:
这不仅仅是破折号与下划线的问题:
It's not just dash vs. underscore:
谷歌过去并没有将下划线视为单词分隔符,我认为这非常疯狂,但显然现在它这样做了。 由于这段历史,破折号是首选。 尽管从 SEO 的角度来看,现在允许使用下划线,但我仍然认为破折号是最好的。
一个好处是,普通的半不懂电脑的网络冲浪者更有可能在键盘上输入破折号,他们甚至可能不知道下划线是什么。
Google did not treat underscore as a word separator in the past, which I thought was pretty crazy, but apparently it does now. Because of this history, dashes are preferred. Even though underscores are now permissible from an SEO point of view, I still think that dashes are best.
One benefit is that your average semi-computer-illiterate web surfer is much more likely to be able to type a dash on the keyboard, they may not even know what the underscore is.
这只是一种猜测,但他们似乎选择了人们最有可能不会在名称中使用的名称。 这样您就可以拥有一个包含连字符的名称,并且仍然使用下划线作为单词分隔符,例如 UseTwo-wayLinks 可以转换为 use_two-way_links。
在您的示例中, /about-us 将是一个名为连字符“about-us”的目录(如果存在这样的单词,并且 /about_us 将是一个名为两个单词短语“about us”的目录,转换为单个字符串非白色字符。
This is just a guess, but it seems they picked the one that people most probably wouldn't use in a name. This way you can have a name that includes a hyphenated word, and still use the underbar as a word delimiter, e.g. UseTwo-wayLinks could be converted to use_two-way_links.
In your example, /about-us would be a directory named the hyphenated word "about-us" (if such a word existed, and /about_us would be a directory named the two-word phrase "about us" converted to a single string of non-white characters.
我以前一直使用下划线,现在我只将它们用于网站中我不希望任何人直接链接的部分,js文件,css,...等。
从SEO的角度来看,破折号似乎成为处理它的首选方式,有关详细说明,来自马嘴 http: //www.mattcutts.com/blog/dashes-vs-underscores/。
似乎出现的另一个问题(更多的是公众而不是程序员)是,当带下划线的超链接加下划线时,您看不到下划线。 高级用户会解决这个问题,但 Joe Public 可能不会。
尽管如此,在代码中仍然优先使用下划线而不是破折号——程序员理解它们,但大多数其他人不理解。
I used to use underscores all the time, now I only use them for parts of a web site that I don't want anyone to directly link, js files, css, ... etc.
From an SEO point of view, dashes seem to be the preferred way of handling it, for a detailed explanation, from the horses mouth http://www.mattcutts.com/blog/dashes-vs-underscores/.
The other problem that seems to occur, more with the general public than programmers, is that when a hyperlink with underscores is underlined, you can't see the underscore. Advanced users will work it out, but Joe Public probably won't.
Still use underscores in code in preference to dashes though - programmers understand them, most other people don't.
以下是支持使用破折号的几点:
Here are a few points in favor of the dashes:
我个人会避免所有破折号和下划线,并选择 camelCase 或 PascalCase(如果在代码中)。
维基百科关于驼峰命名法的文章解释了其起源背后的一些原因。 他们相当于
伸手去拿 _ 键
施乐
没有下划线键。
如果用户要查看该字符串,那么我不会执行上述任何操作并使用“关于我们”。 或“关于我们”(如果我不得不这样做),因为驼峰式命名法已在某些领域(例如产品名称)中广泛使用。 即ThinkPad、TiVo
I personally would avoid all dashes and underscores and opt for camelCase or PascalCase if its in code.
The Wikipedia article on camelCase explains a bit of the reasoning behind it's origins. They amount to
reaching for the _ key
readability
that had no underscore key.
If the user is to see the string then I'd do none of the above and use "About us." or "AboutUs" if I had to as camelCase has spread to common usage in some areas such as product names. i.e ThinkPad, TiVo
就我个人而言,我会避免使用 about-us 或 about_us,而只使用 about。
Personally, I'd avoid using about-us or about_us, and just use about.
一些较旧的 Web 托管和 DNS 服务器实际上在解析 URL 的下划线时存在问题,因此这可能会在此类约定中发挥作用。
Some older web hosting and DNS servers actually have problems parsing underscores for URLs, so that may play a part in conventions like these.
我认为从用户角度来看,dash 更好,并且不会干扰 SEO。
不确定下划线约定从何处或为何开始。
知识渊博一点辩论
I think dash is better from a user perspective and it will not interfere with SEO.
Not sure where or why the underscore convention started.
A little more knowledgeable debate
我更喜欢破折号,因为下划线可能会在一定程度上被链接下划线掩盖。 文本 URL 主要是为了一目了然,而不是在语法上正确,因此保留破折号用于连字符的单词的论点是有限的。
文本 URL 的准确性很重要的地方是在向某人朗读时,在这种情况下,您不想将下划线与空格混淆(反之亦然)。
我还发现破折号更美观(如果这有什么意义的话)。
I prefer dashes on the basis that an underscore might be obscured to an extent by a link underline. Textual URLs are primarily for being recognised at a glance rather than being grammatically correct so the argument for preserving dashes for use in hyphenated words is limited.
Where the accuracy of a textual URL is important is when reading it out to someone, in which case you don't want to confuse an underscore for a space (or vice-versa).
I also find dashes more aesthetically pleasing, if that counts for anything.
对于最终用户视图,我更喜欢“关于我们”或“关于我们”而不是“about_us”
For end-user view i prefer "about-us" or "about us" not "about_us"
来自 Google 网站站长中心
From Google Webmaster Central