这些是我在 .htaccess
中的当前规则。基本上,我想将我的整个站点从 domain1.com
重定向到 domain2.com
,但以下情况除外:
/offers
文件夹中的所有文件/页面/page/company-a 页面
当我访问 www.domain1.com/page/company-a
时,我被重定向到 domain2.com/index.php
。
感谢任何建议。
RewriteCond %{REQUEST_URI} !^/offers
RewriteCond %{REQUEST_URI} !^/page/company-a
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [L,R=301]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
最佳答案
使用 THE_REQUEST
变量代替 REQUEST_URI
。 THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,并且在执行某些重写规则后它不会被覆盖。
RewriteEngine On
RewriteCond %{THE_REQUEST} !\s/+(offers|page/company-a) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain1\.com$ [NC]
RewriteRule ^ http://www.domain2.com%{REQUEST_URI} [L,R=301,NE]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
确保在测试时清除浏览器缓存。
关于php - .htaccess 异常规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44362837/