.htaccess too many redirects. Redirect all users except ip to different part of website

I’m trying to make a website where all users are redirected to a specific part in the domain so that they can see a “comming soon” page. While some ip addresses can still access the normal website so that they can see how it is going to look.

What I’m trying to do: create a wordpress website in the root of public_html, create a soon directory in public_html and redirect all users except a few ip’s to http://www.domain.com/soon/index.html

Read More

My .htaccess looks as followed:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.2.3.4
RewriteRule (.*) http://www.domain.com/soon/index.html [R=302,L]

However whenever I go to the website to test it out it tells me:
ERR_TOO_MANY_REDIRECTS

Is there something I’m doing wrong in my .htaccess?

Related posts

2 comments

  1. Try this:

    RewriteEngine On    
    RewriteBase /
    RewriteCond %{REMOTE_ADDR} !^1.2.3.4$
    RewriteRule .? /soon/index.html [L]
    
  2. Use this rule as your very first rule in your .htaccess:

    RewriteEngine On
    
    RewriteCond %{REMOTE_ADDR} !^(1.2.3.4|11.22.33.44)$
    RewriteCond %{REQUEST_URI} !.(?:jpe?g|gif|bmp|png|tiff|css|js)$
    RewriteRule !^soon/index.html$ http://www.domain.com/soon/index.html [R=302,L,NC]
    
    • Variable REMOTE_ADDR matches client’s IP in a web request.
    • RewriteCond %{REQUEST_FILENAME} !-f is needed to avoid redirecting for css/js/image files and /soon/index.html file.

Comments are closed.