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

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

问题描述

何时应在URL中使用斜杠?例如-我的网址应该是/about-us/还是/about-us?

我完全了解与SEO相关的问题-重复的内容和规范的事情;我正在尝试找出在单独正确地投放页面 的情况下应该使用哪一个.

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

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

解决方案

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

基本上,URL格式来自相同的UNIX格式的文件和文件夹,此后在DOS系统上,最后适用于Web.

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

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

另一个值得阅读的好资源:维基百科:URI方案

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

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

也:

这是我们经常听到的问题.继续回答!从历史上看,带有斜杠的URL表示目录和不带斜杠的URL代表目录是很常见的 表示一个文件:

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

http://example.com/foo (不带斜杠,通常是文件)

来源: Google WebMaster Central博客-至斜线还是不斜线

最后:

  1. URL末尾的斜杠使地址看起来漂亮".

  2. 在末尾没有斜杠且没有扩展名的URL看起来有些怪异".

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

但是无论环境如何,我都是Web最佳实践的拥护者. 就像您所说的不带扩展名的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.

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

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