301重定向 - .htaccess中的preg匹配规则?

时间:2016-04-15 08:18:46

标签: .htaccess redirect

我希望实现具有以下结构的所有链接

http://www.example.com/hair-removal/
http://www.example.com/hair-removal/sub
http://www.example.com/hair-removal/sub/supersub

被重定向到

http://www.example.com/hair-removal-new/
http://www.example.com/hair-removal-new/sub
http://www.example.com/hair-removal-new/sub/supersub

如何使用htaccess文件实现此目的?

2 个答案:

答案 0 :(得分:1)

如果您只想将其用于/hair-removal/*并保持其他网址不变,请使用以下命令:

RewriteRule ^hair-removal/(.*)$ /hair-removal-new/$1 [R=301,L]

答案 1 :(得分:0)

试一试:

RewriteRule ^([^/]+)/ $1-new/ [R=301,NC,L]
相关问题