Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 301 htaccess中url模式的重定向_.htaccess_Redirect - Fatal编程技术网

.htaccess 301 htaccess中url模式的重定向

.htaccess 301 htaccess中url模式的重定向,.htaccess,redirect,.htaccess,Redirect,以前我在主域上安装了vbulletin论坛。现在我已经用WP博客取代了它,并将论坛转移到了子文件夹。WP和vB都有单独的htaccess文件。请帮助我将旧论坛URL重定向到新论坛URL 旧的url模式: www.domain.com/f1/post-title/ www.domain.com/f2/post-title/ www.domain.com/f3/post-title/ www.domain.com/forums/f1/post-title/ www.domain.com/forum

以前我在主域上安装了vbulletin论坛。现在我已经用WP博客取代了它,并将论坛转移到了子文件夹。WP和vB都有单独的htaccess文件。请帮助我将旧论坛URL重定向到新论坛URL

旧的url模式:

www.domain.com/f1/post-title/
www.domain.com/f2/post-title/
www.domain.com/f3/post-title/
www.domain.com/forums/f1/post-title/
www.domain.com/forums/f2/post-title/
www.domain.com/forums/f3/post-title/
新的url模式:

www.domain.com/f1/post-title/
www.domain.com/f2/post-title/
www.domain.com/f3/post-title/
www.domain.com/forums/f1/post-title/
www.domain.com/forums/f2/post-title/
www.domain.com/forums/f3/post-title/

请有人帮我修改正确重定向的规则。还要提到放置代码的htaccess(WP或vB)。提前感谢。

它需要放在域根文件夹的
.htaccess
上。

因此,如果您的根文件夹是
/home/yourcount/public\u html/
,则在该文件夹的
.htaccess

这将按照您上面的要求,将任何
论坛/主题
重定向到
论坛/论坛/主题

Options +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /

RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]
我可以使用
([^/]+)
两次,但是既然你提到你现在在根目录中有一个WordPress,那么你应该需要一个更具体的规则来处理上面提到的第一个文件夹

这将匹配论坛id aka
f1
f2
。。。不超过任意数量的数字:

(f\d+)
这将获得任何非
/
的内容,因此它将获得帖子id和标题

([^/]+)
如果您的
.htaccess
文件中有更多规则,请确保将此规则放置在
上的
重写引擎之后
上的任何其他规则之前,这样它就不会与其他规则冲突,并按照您的要求重定向:

RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]