301 redirect with complex directory regex

泄露秘密 提交于 2020-02-05 05:14:48

问题


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

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

REDIRECT FROM

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

REDIRECT TO

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

EDIT: 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?

Thanks!


回答1:


You can add these new rules:

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


来源:https://stackoverflow.com/questions/26249516/301-redirect-with-complex-directory-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!