.htaccess htcaccess外部重定向不排除URI
我试图从基于htaccess的重定向中排除几个URI 我的htaccess指令如下.htaccess htcaccess外部重定向不排除URI,.htaccess,mod-rewrite,redirect,external,.htaccess,Mod Rewrite,Redirect,External,我试图从基于htaccess的重定向中排除几个URI 我的htaccess指令如下 <IfModule mod_rewrite.c> RewriteEngine on # RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC] RewriteRule !=/test$ http://domain2.com [L,R=301,NC] #
<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule !=/test$ http://domain2.com [L,R=301,NC]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
重新启动发动机
#
重写cond%{HTTP_HOST}^(www\)?domain1.com$[NC]
重写规则=/测试美元http://domain2.com [L,R=301,NC]
#
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}=/图标文件
重写规则^(.*)$index.php?q=$1[L,QSA]
这有什么不对?有什么建议吗
我也尝试过另一种方式
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/test
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
重新启动发动机
重写cond%{REQUEST_URI}=/测试
重写规则(.*)http://domain2.com? [R=301,L]
#将表单“x”的URL重写为表单“index.php?q=x”。
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}=/图标文件
重写规则^(.*)$index.php?q=$1[L,QSA]
在执行外部重定向(排除URI)时,测试无效。如果我在做一个内部重写,它可以正常工作。也许这样可以:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/test
# Add next line
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
Options+FollowSymlinks
重新启动发动机
重写cond%{REQUEST_URI}/测试
#添加下一行
重写cond%{REQUEST_URI}!索引\.php[NC]
重写规则(.*)http://domain2.com? [R=301,L]
#将表单“x”的URL重写为表单“index.php?q=x”。
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}=/图标文件
重写规则^(.*)$index.php?q=$1[L,QSA]
这对排除测试URI有效,但domain1.com没有重定向,因为index.php处于排除状态。条件仅对下一条规则有效。在本例中,用于外部重定向。不要适用于其他规则。在进行任何测试之前,请确保清除浏览器的缓存。