连字符,下划线或驼峰中的URI字分隔符? [英] Hyphen, underscore, or camelCase as word delimiter in URIs?
问题描述
我设计了一个Intranet应用基于HTTP的API。我意识到这是在事物的宏伟计划一个pretty小的关注,但为我应该用连字符,下划线或驼峰分隔词语的URI的
I'm designing an HTTP-based API for an intranet app. I realize it's a pretty small concern in the grand scheme of things, but: should I use hyphens, underscores, or camelCase to delimit words in the URIs?
下面是我最初的想法:
驼峰
- 可能出现的问题,如果服务器不区分大小写
- 似乎有相当wides查询字符串键$ P $垫使用(http://api.example.com? SEARCHQUERY = ...),而不是在其他URI部分
- possible issues if server is case-insensitive
- seems to have fairly widespread use in query string keys (http://api.example.com?searchQuery=...), but not in other URI parts
连字符
- 更美观比其他替代赏心悦目
- 似乎被广泛使用在URI 的路径部分
- 从来没有见过在野外复姓查询字符串键
- 的可能的更好的搜索引擎优化(这可能是一个神话)
- more aesthetically pleasing than the other alternatives
- seems to be widely used in the path portion of the URI
- never seen hyphenated query string key in the wild
- possibly better for SEO (this may be a myth)
下划线
- 可能更容易编程语言来处理
- 几种流行的API(脸谱,Netflix公司,StackExchange等)所使用的URI的所有部分下划线。
我倾向于下划线的一切。大多数的大玩家使用它们的事实是引人注目(见 http://stackoverflow.com/a/608458/360570一>)。
I'm leaning towards underscores for everything. The fact that most of the big players are using them is compelling (see http://stackoverflow.com/a/608458/360570).
推荐答案
您应在抓取Web应用程序的URL中使用连字符。为什么?因为连字符分隔单词(使得搜索引擎可以索引个体话),并且不是单词字符。下划线是一个单词字符,这意味着它应该被视为一个字的一部分。
You should use hyphens in a crawlable web application URL. Why? Because the hyphen separates words (so that a search engine can index the individual words), and is not a word character. Underscore is a word character, meaning it should be considered part of a word.
双击此:驼峰结果
在Chrome中双击此:under_score结果
在Chrome中双击此:连字符ated
Double-click this in Chrome: camelCase
Double-click this in Chrome: under_score
Double-click this in Chrome: hyphen-ated
请参阅如何铬(我听到谷歌也使得搜索引擎)只是认为其中之一是两个词?
See how Chrome (I hear Google makes a search engine too) only thinks one of those is two words?
驼峰
和下划线
还要求用户使用<大骨节病>移动骨节病>键,而复姓
没有。
camelCase
and underscore
also require the user to use the shift key, whereas hyphenated
does not.
所以,如果你要在抓取Web应用程序中使用连字符,你为什么会费心做一些内联网的应用有什么不同?少了一个要记住。
So if you should use hyphens in a crawlable web application, why would you bother doing something different in an intranet application? One less thing to remember.
这篇关于连字符,下划线或驼峰中的URI字分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!