.htaccess 301重定向;排除目录和获取参数

时间:2017-02-16 15:11:39

标签: apache .htaccess redirect mod-rewrite

我在.htacces中使用以下内容来制作301域重定向:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^exa-mple.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.exa-mple.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

我想要排除包含目录/test/或获取参数?test= / &test=的网址。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

你可以这样排除它们:

RewriteEngine on

RewriteCond %{QUERY_STRING) !(?:^|&)test= [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?exa-mple\.com$ [NC]
RewriteRule !^test/ http://www.example.com%{REQUEST_URI} [L,R=301,NC,NE]

答案 1 :(得分:0)

要排除目录并获取参数,请在重写文件正上方添加以下条件

 #exclude /test
RewriteCond %{REQUEST_URI} !^/test/
#exclude urls that contain test query key ?test
RewriteCond %{THE_REQUEST} !/\?test [NC]
相关问题