These are my current rules in .htaccess. Basically, I want to redirect my entire site from domain1.com to domain2.com except for the following conditions:
all files/pages inside /offers folder
the page at /page/company-a
When I access www.domain1.com/page/company-a, I am redirected to domain2.com/index.php instead.
Any advice appreciated.
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]
Use THE_REQUEST variable instead of REQUEST_URI. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.
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]
Make sure to clear your browser cache while testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With