mod_rewrite,尾部斜杠 - 一行而不是两行?
我一直在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着斜杠可能存在也可能不存在。
This means that the slash may or may not be present.