.htaccess exclusion rules not working

These are my current rules in .htaccess

. Basically, I want to redirect the entire site from domain1.com

to domain2.com

except for the following conditions:

  • all files / pages inside a folder /offers

  • page /page/company-a

When I access www.domain1.com/page/company-a

, I am redirected to instead domain2.com/index.php

.

Any advice is 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]

      

+3


source to share


1 answer


Use THE_REQUEST

instead REQUEST_URI

. THE_REQUEST

variable is the original request that Apache received from your browser and it is not rewritten after some rewrite rules are followed.

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]

      



Be sure to clear your browser cache during testing.

+2


source







All Articles