尾部斜杠:是还是否?

发布于 2024-09-05 23:59:16 字数 356 浏览 4 评论 0原文

我正在开发一个新项目,使用 Apache 的 mod_rewrite 和 PHP 来获取漂亮的 URL。

我的网址如下所示:
http://example.tld/foo/bar/1/etc

请注意,没有尾部斜杠(这就是我在 href 属性中编写的方式s)。

但是,我也允许 http://example.tld/foo/bar/1/etc/ (尾部斜杠)。

这是不好的做法吗?我想知道是否只允许一种方式会更好,或者我是否最好在默认情况下在所有链接中使用尾部斜杠。

谢谢。

I'm working on a new project, using Apache's mod_rewrite and PHP to get pretty URLs.

Here's what my URLs look like:
http://example.tld/foo/bar/1/etc

Notice that there's no trailing slash (that's the way I write it in the href attributes of <a>s).

However, I'm also allowing http://example.tld/foo/bar/1/etc/ (trailing slash).

Is this bad practice? I'm wondering if it would be better to only allow one way or if I'd better use trailing slashes in all my links, by default.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝礼 2024-09-12 23:59:16

在文档中使用相对链接时,尾部斜杠可能会出现问题,因为浏览器会将 /etc 视为目录。

我会定义一种方式,并为另一种方式设置外部重定向。

Trailing slashes can be a problem when using relative links in the document, as the browser will then treat /etc as a directory.

I would define one way, and set up an external redirect for the other.

黑色毁心梦 2024-09-12 23:59:16

尾部斜杠通常表示目录,没有尾部斜杠则表示文件。

允许带或不带尾部斜杠都会对搜索引擎排名产生负面影响,因为相同的内容会被索引两次。坚持使用其中一个,如果用户请求另一个,则执行 301 重定向。

A trailing slash usually indicates a directory, without a trailing slash it indicates a file.

Allowing both with and without trailing slash will have a negative effect on your search engine ranking, because the same content is indexed twice. Stick to one, and do a 301 redirect if a user requests the other.

樱娆 2024-09-12 23:59:16

我想说的是,为了保持一致性,只允许您自己使用,然后将其重定向(301 )错误的(带尾随)到正确的(不带尾随),这样您就不会重复内容

当然,什么是对什么是错完全取决于你。

I'd say for consistency only allow what you use yourself, then have it redirect (301) the wrong (with trailing) to the right one (without trailing), this way you won't have duplicate content either.

Of course whats right and wrong is entirely up to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文