I need redirect all traffic to apache website except some IP to courtesy page, I tried to put these lines at the bottom of .htaccess
RewriteCond %{REMOTE_ADDR} !^1.2.3.4
RewriteRule .* /coming-soon.html [R=301,NC]
With my IP 1.2.3.4
the website works, other IP instead have too many redirect
but into address bar appear https://www.example.com/coming-soon.html
, where am i wrong?
Thanks
CodePudding user response:
Isn't the message itself crystal clear? You implemented an endless redirection loop. The URL /coming-soon.html
will again get redirected by your rule, since the IP address has not changed. You need a second condition to prevent that:
RewriteCond %{REMOTE_ADDR} !^1.2.3.4
RewriteCond %{REQUEST_URI} !^/coming-soon\.html$
RewriteRule .* /coming-soon.html [R=301,NC]
This is a variant with a few additional changes that probably do make sense:
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteCond %{REQUEST_URI} !^/coming-soon\.html$
RewriteRule ^ /coming-soon.html [R=301,L]