在 URL 中添加尾部斜杠
我当前的 .htaccess 文件如下所示:
RewriteEngine on
RewriteBase /
Options +FollowSymLinks -Indexes
RewriteRule ^video/(.*)$ video.php?id=$1 [L]
RewriteRule ^video/(.*)$([a-zA-Z0-9]+) video.php?id=$1 [L]
RewriteRule ^tag/(.*)/page-(.*)/$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)/page-(.*)$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)?$ tag.php?tag=$1
RewriteRule ^page/(.*)$ page.php?id=$1 [L]
RewriteRule ^feed feed.php [L]
我想向我的所有网址添加斜杠,
如下所示:
> example.com/video/video_id/
>
> example.com/tag/keyword/
>
> example.com/tag/keyword/page-2/ (3... and so on...)
>
> example.com/page/name/
>
> example.com/feed/
我想将当前链接重定向到新的斜杠网址
有人可以帮助我吗?
My current .htaccess file looks like this:
RewriteEngine on
RewriteBase /
Options +FollowSymLinks -Indexes
RewriteRule ^video/(.*)$ video.php?id=$1 [L]
RewriteRule ^video/(.*)$([a-zA-Z0-9]+) video.php?id=$1 [L]
RewriteRule ^tag/(.*)/page-(.*)/$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)/page-(.*)$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)?$ tag.php?tag=$1
RewriteRule ^page/(.*)$ page.php?id=$1 [L]
RewriteRule ^feed feed.php [L]
i want to add a slash to all my url's
like this:
> example.com/video/video_id/
>
> example.com/tag/keyword/
>
> example.com/tag/keyword/page-2/ (3... and so on...)
>
> example.com/page/name/
>
> example.com/feed/
And i want to redirect my current links to the new slash url's
Can somebody help me, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前的 htaccess 文件支持尾随 /,尽管您可能更喜欢
这样,这样您就不必处理 video.php 中的 /
只需将所有网址更新为
example.com/video/video_id/
而不是您正在使用的任何内容(您的框架/平面 HTML 文件)中的example.com/video/video_id
。您的旧网址仍然有效。如果您确实想重定向它们,您可以:
[NC]
表示无大小写检查(因此 /VIDEO)可以工作。[R=301]
表示永久重定向(对于 SEO 有用)。仔细检查并扩展您的其他规则。
编辑:
抱歉,我认为之前不太正确。请尝试以下操作:
Your current htaccess file supports a trailing / although you probably would prefer
So that you don't have to handle the / in video.php
Just update all of your URLs to be
example.com/video/video_id/
instead ofexample.com/video/video_id
in whatever you are using (your framework/flat HTML files).Your old URLs will still work. If you really want to redirect them, you can:
The
[NC]
means No-case checking (so /VIDEO) would work. The[R=301]
means permanent redirect (useful for SEO).Go through and expand for your other rules.
Edit:
Sorry, I don't think it was quite right before. Try the following: