Force user to a single site when visiting over a specific domain via htaccess

Viewed 52

I try to force a user which is coming via a specific domain example-page.com to always get redirected to /countdown

My approach was the the following:

RewriteCond %{HTTP_HOST} ^example-page\.com [NC, OR]
RewriteCond %{HTTP_HOST} ^www.example-page\.com [NC]
RewriteCond %{REQUEST_URI} !^/countdown
RewriteRule ^(.*)$ https://www.example-page.com/countdown [L,R=301]

But for some reason I always get a "Too many redirects error". I get redirected to the https://www.example-page.com/countdown but somehow the RewriteCond is triggered again but it should not because of the RewriteCond %{REQUEST_URI} !^/countdown.

2 Answers

Could you please try following, with your shown samples. Please keep these Rules at top of your htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?example-page\.com [NC]
RewriteCond %{REQUEST_URI} !^/countdown
RewriteRule ^ https://www.example-page.com/countdown [L,R=301]

Also why you are getting error because you have space between NC and OR(NC, OR) which is causing that 500 internal error.

You may try this rule:

RewriteCond %{HTTP_HOST} ^(?:www\.)?example-page\.com [NC]
RewriteCond %{THE_REQUEST} !\s/countdown [NC]
RewriteRule ^ https://www.example-page.com/countdown [L,R=301]

Make sure to test if after clearing your browser cache.

Related