mod_rewrite,尾部斜杠 - 一行而不是两行?

发布于 2024-10-29 04:25:21 字数 725 浏览 0 评论 0原文

我一直在使用 mod_rewrite 使用 .htaccess 来翻译一些目录 - 目的是改进 SEO 并生成更友好/更令人难忘的 URL。

目前我无法解决的唯一问题是尾随斜杠。我想要的行为是,您应该能够访问带或不带尾部斜杠的链接,只是为了减少错过的流量。

我的真实网址是:

http://www.mydomain.com/shipyard/index.php

我希望人们能够通过以下方式访问它:

http://www.mydomain.com/shipyard/ 
http://www.mydomain.com/shipyard
http://www.mydomain.com/ships/ 
http://www.mydomain.com/ships 

当然,前两个被覆盖,因为那实际上是一个真实且可访问的网址,但我计划告诉谷歌访问该页面的最佳方式正在使用 /ships (无需移动目录、破坏现有链接等)。

到目前为止我想出的最好的办法是:

RewriteRule ^ships/$ /shipyard/index.php [L]
RewriteRule ^ships$ /shipyard/index.php [L]

但是我只知道我使用的是两行,而只需要一根,但无论我尝试什么,我都无法得到这一行!我知道我错过了一些非常基本和/或明显的东西,但我需要一个指针......谢谢!

I have been playing with mod_rewrite using .htaccess to translate some directories - for purposes of both improved SEO and also to produce friendlier/more memorable URLs.

The only problem I can't crack at the moment is with trailing slashes. The behavoir I want is that you should be able to access the link with or without a trailing slash, just to cut down on missed traffic.

My real url is as:

http://www.mydomain.com/shipyard/index.php

I would like people to be able to access it via:

http://www.mydomain.com/shipyard/ 
http://www.mydomain.com/shipyard
http://www.mydomain.com/ships/ 
http://www.mydomain.com/ships 

Of course, the top two are covered because thats actually a real and accessible URL, but I plan to tell Google that the best way to get at the page is using /ships (without having to move directories, break existing links etc).

The best I came up with so far was:

RewriteRule ^ships/$ /shipyard/index.php [L]
RewriteRule ^ships$ /shipyard/index.php [L]

However I just KNOW that i'm using two lines where only one is needed, but whatever I tried, I couldn't get the one! I know i'm missing something incredibly basic and/or obvious, but I need a pointer... Thanks!

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

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

发布评论

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

评论(1

凉墨 2024-11-05 04:25:21
RewriteRule ^ships(/)?$ /shipyard/index.php [L]

这意味着斜杠可能存在也可能不存在。

RewriteRule ^ships(/)?$ /shipyard/index.php [L]

This means that the slash may or may not be present.

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