1

我当前的 .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/

我想将我当前的链接重定向到新的斜杠 url

有人可以帮我吗?

4

1 回答 1

2

您当前的 htaccess 文件支持尾随 / 尽管您可能更喜欢

RewriteRule ^video/(.*)/$ video.php?id=$1 [L]

这样您就不必处理 video.php 中的 /

只需将所有 URL 更新为您正在example.com/video/video_id/使用example.com/video/video_id的任何内容(您的框架/平面 HTML 文件)。

您的旧网址仍然可以使用。如果你真的想重定向它们,你可以:

RewriteCond %{REQUEST_URI} ^video/ [NC]
RewriteRule ^video/(.*)$ video.php?id=$1 [L,R=301]

[NC]意味着无案例检查(所以/VIDEO)会起作用。这[R=301]意味着永久重定向(对 SEO 有用)。

浏览并扩展您的其他规则。

编辑:

对不起,我认为以前不太对。尝试以下操作:

RewriteEngine on
RewriteBase /

Options +FollowSymLinks -Indexes

RewriteCond %{REQUEST_URI} ^video/ [NC]
RewriteRule ^video/(.*)$ video/$1/ [L,R=301]
RewriteRule ^video/(.*)/$ video.php?id=$1 [L]

RewriteCond %{REQUEST_URI} ^tag/ [NC]
RewriteRule ^tag/(.*)/page-(.*)$ tag/$1/page-$2/ [L,R=301]
RewriteRule ^tag/(.*)/page-(.*)/$ tag.php?tag=$1&page=$2 [L]

...
于 2010-10-25T18:27:02.983 回答