301重定向与复杂的目录正则表达式重定向、复杂、目录、正则表达式

2023-09-02 09:59:01 作者:[时光会咬人]

我使用的文件夹重定向伟大的工程@ anubhava的解决方案。 301从一个目录重定向到另一个

I am using @anubhava's solution for folder redirect which works great. 301 redirect from one directory to another

我意识到,我还需要有一个301重定向以下

I realised that I also need to have a 301 redirect for the following

重定向

1) www.example.com/directory1/dirA/ 
2) www.example.com/directory1/dirB/ 

重定向到

1) www.example.com/directory2/new-path-dirA/ 
2) www.example.com/directory2/new-path-dirB/ 

编辑:我有很多这样的重定向(约40),想知道是否有办法有1重写规则 - 而不是单独的规则

I have a lot of these redirects (about 40) and was wondering if there is way to have 1 Rewrite rule - instead of separate rules?

谢谢!

推荐答案

您可以添加这些新的规则:

You can add these new rules:

RewriteRule ^directory1/([^/]+)/(.*)$ /directory2/new-path-$1/$2 [NC,L,NE,R=301]
 
精彩推荐
图片推荐