我什么时候应该在我的 URL 中使用尾部斜杠? [英] When should I use a trailing slash in my URL?

查看:34
本文介绍了我什么时候应该在我的 URL 中使用尾部斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候应该在 URL 中使用尾部斜杠?例如 - 我的 URL 应该像 /about-us/ 还是像 /about-us?

我完全了解与 SEO 相关的问题 - 重复的内容和规范的事物;我试图弄清楚在单独正确提供页面的上下文中我应该使用哪个.

例如,我的同事认为末尾的斜杠表示它是文件夹"-目录",因此这不是正确的样式.但我认为最后没有斜线 - 这也不太正确,因为它几乎看起来像一个文件夹,但它不是,它也不是一个普通文件,而是一个没有扩展名的文件名.

是否有正确的方法知道使用哪个?

解决方案

在我个人看来,尾部斜杠被滥用了.

基本上,URL 格式来自相同的 UNIX 格式的文件和文件夹,后来在 DOS 系统上,最后适应了网络.

<块引用>

这本书在类 Unix 操作系统上的典型 URL 是文件路径,例如 file:///home/username/RomeoAndJuliet.pdf,标识保存在本地硬盘文件中的电子书.

来源:维基百科:统一资源标识符

另一个不错的阅读来源:维基百科:URI Scheme

<块引用>

根据 RFC 1738,它在 1994 年定义了 URL,当资源包含对其他资源的引用时,它们可以使用相对链接来定义第二个资源的位置,就像在说,与这个资源在同一个地方,除了以下相对路径".它接着说,这样的相对 URL 依赖于包含相对链接所基于的层次结构的原始 URL,并且 ftp、http、和文件 URL 方案是一些可以被视为层次结构的示例,层次结构的组件由/"分隔.

来源:维基百科统一资源定位符(URL)

还有:

<块引用>

这是我们经常听到的问题.继续寻找答案!从历史上看,带有尾部斜杠的 URL 表示目录,而没有尾部斜杠的 URL 表示目录是很常见的.表示一个文件:

http://example.com/foo/(带有斜杠,通常是一个目录)

http://example.com/foo(没有尾部斜杠,通常是一个文件)

来源:Google 网站管理员中心博客 - 至斜线或不斜线

最后:

  1. 网址末尾的斜线使地址看起来漂亮".

  2. 结尾没有斜线且没有扩展名的网址看起来有些奇怪".

  3. 您永远不会命名您的 CSS 文件(例如)http://www.sample.com/stylesheet/ 你愿意吗?

但无论环境如何,我都是网络最佳实践的支持者.就像你说的不带扩展名的 URL 一样,它可能很奇怪和不清楚.

When should a trailing slash be used in a URL? For example - should my URL look like /about-us/ or like /about-us?

I am fully aware of the SEO-related issues - duplicate content and the canonical thing; I'm trying to figure out which one I should use in the context of serving pages correctly alone.

For example, my colleague is thinking that a trailing slash at the end means it's a "folder" - a "directory", so this is not a correct style. But I think that without a slash in the end - it's not quite correct either, because it almost looks like a folder, but it isn't and it's not a normal file either, but a filename without extension.

Is there a proper way of knowing which to use?

解决方案

In my personal opinion trailing slashes are misused.

Basically the URL format came from the same UNIX format of files and folders, later on, on DOS systems, and finally, adapted for the web.

A typical URL for this book on a Unix-like operating system would be a file path such as file:///home/username/RomeoAndJuliet.pdf, identifying the electronic book saved in a file on a local hard disk.

Source: Wikipedia: Uniform Resource Identifier

Another good source to read: Wikipedia: URI Scheme

According to RFC 1738, which defined URLs in 1994, when resources contain references to other resources, they can use relative links to define the location of the second resource as if to say, "in the same place as this one except with the following relative path". It went on to say that such relative URLs are dependent on the original URL containing a hierarchical structure against which the relative link is based, and that the ftp, http, and file URL schemes are examples of some that can be considered hierarchical, with the components of the hierarchy being separated by "/".

Source: Wikipedia Uniform Resource Locator (URL)

Also:

That is the question we hear often. Onward to the answers! Historically, it’s common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file:

http://example.com/foo/ (with trailing slash, conventionally a directory)

http://example.com/foo (without trailing slash, conventionally a file)

Source: Google WebMaster Central Blog - To slash or not to slash

Finally:

  1. A slash at the end of the URL makes the address look "pretty".

  2. A URL without a slash at the end and without an extension looks somewhat "weird".

  3. You will never name your CSS file (for example) http://www.sample.com/stylesheet/ would you?

BUT I'm being a proponent of web best practices regardless of the environment. It can be wonky and unclear, just as you said about the URL with no ext.

这篇关于我什么时候应该在我的 URL 中使用尾部斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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