Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htcaccess外部重定向不排除URI_.htaccess_Mod Rewrite_Redirect_External - Fatal编程技术网

.htaccess htcaccess外部重定向不排除URI

.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] #

我试图从基于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]
        #


          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处于排除状态。条件仅对下一条规则有效。在本例中,用于外部重定向。不要适用于其他规则。在进行任何测试之前,请确保清除浏览器的缓存。