这些是.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]
答案 0 :(得分:2)
使用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]
确保在测试时清除浏览器缓存。