如何在htaccess中重写除1个子目录之外的整个目录?

时间:2014-05-16 18:38:07

标签: regex apache .htaccess redirect url-rewriting

如何重写整个"工程"目录到新的URL保存为" engineering / tour"子目录应该保留?

我目前有这个重定向整个目录:

RedirectMatch 301 ^/engineering(.*) /academics/academic-areas/engineering-technology-and-environmental-studies/

2 个答案:

答案 0 :(得分:0)

如果你可以使用mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?engineering
RewriteCond %{REQUEST_URI} !^/?engineering/tour
RewriteRule . /academics/academic-areas/engineering-technology-and-environmental-studies/ [R=301,L]

答案 1 :(得分:0)

您只需在规则中添加否定前瞻:

RedirectMatch 301 ^/engineering((?!tour).*) /academics/academic-areas/engineering-technology-and-environmental-studies/