简体   繁体   English

漂亮的网址和尾随斜杠

[英]Pretty urls and trailing slashes

The question is about trailing slashes in URLs. 问题是关于URL中的斜杠。

When we have a directory structure, then it is obvious - / means directory, no slash means resource. 当我们有一个目录结构时,很明显 - /表示目录,没有斜杠表示资源。

However many sites are dynamic and use pretty urls that do not directly reflect their directory structure. 然而,许多站点是动态的,并使用不直接反映其目录结构的漂亮URL。 And in this case most urls are actually requesting resources rather than directories, so a trailing slash is not needed. 在这种情况下,大多数URL实际上是请求资源而不是目录,因此不需要使用尾部斜杠。

My questions is: is it fine to have pretty urls not ending in a trailing slash, and if access to a trailing slash version is attempted to use a 301 redirect to the non-slash version? 我的问题是:如果没有以尾部斜杠结尾的漂亮网址,并且如果尝试使用301重定向到非斜杠版本,是否可以访问尾部斜杠版本?

And a counter question - is it fine to have all pretty urls end with a slash even though they are not directories? 还有一个反问题 - 即使它们不是目录,让所有漂亮的网址都以斜线结尾也没关系?

Google says it's ok (for indexing and searching and all that) Google表示没关系 (用于编制索引和搜索等等)

However, they do mention that behavior like this is treated as duplicate content. 但是,他们确实提到像这样的行为被视为重复内容。 So it's probably better that only one of those schemes actually refer to the content. 因此,这些方案中只有一个实际涉及内容可能更好。 You'd want one of the schemes to redirect to the other. 您希望其中一个方案重定向到另一个。 Whether it should be the one with the trailing slash or not depends on your choice. 是否应该是带斜线的斜杠取决于您的选择。

This article talks about this issue as well : http://www.standardzilla.com/2007/07/09/dont-forget-your-trailing-slash/ It recommends that you end with a trailing slash. 本文也讨论了这个问题: http//www.standardzilla.com/2007/07/09/dont-forget-your-trailing-slash/它建议您以尾部斜杠结尾。 But I think this is dependent more on how your server is setup than anything else. 但我认为这更多地取决于您的服务器设置方式而不是其他任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM