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

Apache .htaccess 301重定向;排除目录并获取参数,apache,.htaccess,redirect,mod-rewrite,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=的URL 我该怎么做?您可以这样排除

我正在.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=
的URL


我该怎么做?

您可以这样排除它们:

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]

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

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