URL:破折号与下划线

发布于 2024-07-07 00:55:44 字数 1752 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

岁月染过的梦 2024-07-14 00:55:44

更好地使用。 - / 作为分隔符,因为 _ 似乎不是分隔符。

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

樱娆 2024-07-14 00:55:44

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.

靖瑶 2024-07-14 00:55:44

杰夫对此有一些想法: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.

篱下浅笙歌 2024-07-14 00:55:44

我更喜欢使用下划线。 首先,它们符合我的常规编程经验 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 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.

岁月无声 2024-07-14 00:55:44

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.

浅唱々樱花落 2024-07-14 00:55:44

下划线替换不允许空格的空格。 破折号(连字符)可以是单词的一部分,因此用连字符连接已经包含连字符的单词是丑陋/令人困惑的。

坏:

/low-budget-movies

好:

/low-budget_movies

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:

/low-budget-movies

Good:

/low-budget_movies
(り薆情海 2024-07-14 00:55:44

这不仅仅是破折号与下划线的问题:

  • 带空格的文本
  • textwithoutspaces
  • 编码%20spaces%20in%20URL
  • underscore_means_space
  • dash-means-space
  • plus+means+space
  • 驼峰命名法
  • PascalCase
  • " 带空格的引用文本" (以及单引号与双引号)
  • 斜杠/意思/空格
  • dot.means.space

It's not just dash vs. underscore:

  • text with spaces
  • textwithoutspaces
  • encoded%20spaces%20in%20URL
  • underscore_means_space
  • dash-means-space
  • plus+means+space
  • camelCase
  • PascalCase
  • " quoted text with spaces" (and single quote vs. double quote)
  • slash/means/space
  • dot.means.space
小兔几 2024-07-14 00:55:44

谷歌过去并没有将下划线视为单词分隔符,我认为这非常疯狂,但显然现在它这样做了。 由于这段历史,破折号是首选。 尽管从 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.

感受沵的脚步 2024-07-14 00:55:44

这只是一种猜测,但他们似乎选择了人们最有可能不会在名称中使用的名称。 这样您就可以拥有一个包含连字符的名称,并且仍然使用下划线作为单词分隔符,例如 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.

流年已逝 2024-07-14 00:55:44

我以前一直使用下划线,现在我只将它们用于网站中我不希望任何人直接链接的部分,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.

梨涡少年 2024-07-14 00:55:44

以下是支持使用破折号的几点:

  • Google 推荐使用破折号而不是下划线 (来源)。
  • 最终用户更熟悉破折号。
  • 在标准键盘上书写破折号更容易(无需 Shift)。
  • 破折号不会隐藏在下划线后面。
  • 在 URL 上下文中,破折号感觉更自然,因为域名中允许使用破折号。

Here are a few points in favor of the dashes:

  • Dashes are recommended by Google over underscores (source).
  • Dashes are more familiar to the end user.
  • Dashes are easier to write on a standard keyboard (no need to Shift).
  • Dashes don't hide behind underlines.
  • Dashes feel more native in the context of URLs as they are allowed in domain names.
硬不硬你别怂 2024-07-14 00:55:44

我个人会避免所有破折号和下划线,并选择 camelCasePascalCase(如果在代码中)。

维基百科关于驼峰命名法的文章解释了其起源背后的一些原因。 他们相当于

  1. 懒惰的程序员,不喜欢
    伸手去拿 _ 键
  2. 潜在的混乱
    施乐
  3. 帕洛阿尔托研究中心的“Alto”​​键盘
    没有下划线键。

如果用户要查看该字符串,那么我不会执行上述任何操作并使用“关于我们”。 或“关于我们”(如果我不得不这样做),因为驼峰式命名法已在某些领域(例如产品名称)中广泛使用。 即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

  1. Lazy programmers who didn't like
    reaching for the _ key
  2. Potential confusion about
    readability
  3. The "Alto" keyboard at xerox PARC
    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

你怎么敢 2024-07-14 00:55:44

就我个人而言,我会避免使用 about-us 或 about_us,而只使用 about。

Personally, I'd avoid using about-us or about_us, and just use about.

ら栖息 2024-07-14 00:55:44

一些较旧的 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.

小清晰的声音 2024-07-14 00:55:44

我认为从用户角度来看,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

我不吻晚风 2024-07-14 00:55:44

我更喜欢破折号,因为下划线可能会在一定程度上被链接下划线掩盖。 文本 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.

美人如玉 2024-07-14 00:55:44

对于最终用户视图,我更喜欢“关于我们”或“关于我们”而不是“about_us”

For end-user view i prefer "about-us" or "about us" not "about_us"

鲜血染红嫁衣 2024-07-14 00:55:44

来自 Google 网站站长中心

考虑在你的文章中使用标点符号
网址。 网址
http://www.example.com/green-dress.html
对我们来说比
http://www.example.com/greendress.html
我们建议您使用连字符 (-)
而不是你的下划线(_)
网址。

From Google Webmaster Central

Consider using punctuation in your
URLs. The URL
http://www.example.com/green-dress.html
is much more useful to us than
http://www.example.com/greendress.html.
We recommend that you use hyphens (-)
instead of underscores (_) in your
URLs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文