301重定向与复杂的目录正则表达式 [英] 301 redirect with complex directory regex

查看:120
本文介绍了301重定向与复杂的目录正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的文件夹重定向伟大的工程@ anubhava的解决方案。 <一href="http://stackoverflow.com/questions/26243074/301-redirect-from-one-directory-to-another/26243281?noredirect=1#comment41165465_26243281">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]

这篇关于301重定向与复杂的目录正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆