Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Apache 重写条件仅运行第一个条件_Apache_.htaccess_Mod Rewrite_Url Rewriting_Url Redirection - Fatal编程技术网

Apache 重写条件仅运行第一个条件

Apache 重写条件仅运行第一个条件,apache,.htaccess,mod-rewrite,url-rewriting,url-redirection,Apache,.htaccess,Mod Rewrite,Url Rewriting,Url Redirection,staging.domain.com应该转到domain.com/blog(最后一条规则),但它会转到domain.com staging.domain.com/category/food应访问domain.com/blog/category/food RewriteEngine On RewriteCond %{HTTP_HOST} ^staging.domain.com/category [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301

staging.domain.com应该转到domain.com/blog(最后一条规则),但它会转到domain.com staging.domain.com/category/food应访问domain.com/blog/category/food

RewriteEngine On

RewriteCond %{HTTP_HOST} ^staging.domain.com/category [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,NC]

RewriteCond %{HTTP_HOST} ^staging.domain.com/work/ [NC]
RewriteRule ^(.*)$ http://domain.com/#work [R=301,NC]


RewriteCond %{HTTP_HOST} ^staging.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/blog [R=301,NC]

如何创建多个规则,或者将它们链接到错误的位置

变量
%{HTTP\u HOST}
仅包含。URL部分对此变量不可用。因此,规则必须作如下修改:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^staging.domain.com$ [NC]
RewriteRule ^((?!work/?).*)$ http://domain.com/blog/$1 [R=301,NC]

RewriteCond %{HTTP_HOST} ^staging.domain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/work/? [NC]
RewriteRule .* http://domain.com/#work [R=301,NC]