URL 结构:小写 VS 大写 [英] URL Structure: Lower case VS Upper case

查看:44
本文介绍了URL 结构:小写 VS 大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我浏览一些网站时,我的脑海中只是触发了它们在 url 中是否有大写和小写组合,例如 http://www.domain.com/Home/Article

现在我知道我们应该总是在 url 中使用小写,但不知道技术原因.我想向您的专家学习,以明确为什么在 url 中使用小写的概念.大写url有什么优缺点.

解决方案

域部分不区分大小写.GoOgLe.CoM 有效.您可以根据需要添加大写字母,但通常没有理由这样做,并且如以下评论所述,可能会损害您的 SEO 排名.

路径部分是否区分大小写,取决于服务器环境和服务器.通常 Windows 机器不区分大小写,而 Linux 机器区分大小写.这意味着您应该坚持使用小写字母,否则您可能会引入一个很难找到的错误(不匹配的大小写在开发服务器上无关紧要).

查询字符串部分对服务器可用.您可以随心所欲地使用混合大小写,或丢弃大小写 (toLowerCase(...)).这也意味着使用 base64 编码的密钥工作.不过,您不能指望用户正确键入.

散列部分(称为片段标识符")仅对客户端代码可用,对服务器不可用.Javascript 可以根据自己的喜好区分情况,浏览器也是如此.url#a 将滚动到 ID 为 a 的元素,但 url#A 不会.

Just trigger in my mind when I was going through some websites were they having upper case and lower case combination in url something like http://www.domain.com/Home/Article

Now as I know we should always use lowercase in url but have not idea about technical reason. I would like to learn from you expert to clear this concept why to use lowercase in url. What are the advantages and disadvantages for upper case url.

解决方案

The domain part is not case sensitive. GoOgLe.CoM works. You can add uppercase as you like, but normally there's not a reason to do so and, as stated in the comments below, may hurt your SEO ranking.

The path part is or is not case sensitive, depending on the server environment and server. Typically Windows machines are case insensitive, while Linux machines are case sensitive. This means that you should stick to lowercase or you risk introducing a bug that's really hard to hunt down (mismatched case that doesn't matter on the dev server).

The query string part is available to the server as it is. You can readily use mixed-case as you like, or discard the case (toLowerCase(...)). This also means that using a base64-encoded keys will work. You can't expect the users to type that correctly, though.

The hash part (called "fragment identifier") is only available to the client code, not to the server. Javascript may distinguish between the cases as it likes, and so does the browser. url#a will scroll to the element with the ID a, but url#A won't.

这篇关于URL 结构:小写 VS 大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆