Home » Other

.htaccess – Redirect Everyone But You

14 May 2009 1 views 2 Comments

Lets begin with the basics. Create a text file and name it .htaccess . Then, lets add some text:

Options +FollowSymlinks
Rewrite Engine on
RewriteCond %{REQUEST_URI] !/maintenance.html$

RewriteRule $ /maintenance.html [R=302,L]

Save your file and lets upload it to the root directory. In other words, it should appear here: www.yourwebsite.com/.htaccess

Once its been uploaded whenever you go to the website it should automatically redirect you and everybody else to maintenance.html. If this page doesn’t exist, you’ll get an error but this is only the test. Once we know the file is working, lets add this extra line right after the REQUEST_URI line:

RewriteCond %[REMOTE_HOST] !^12\.34\.56\.78

Of course you would replace the IP with your own (find it at www.ipchicken.com ). Save the file and reupload it. It should now look like the following:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_HOST} !^12\.34\.56\.78

RewriteRule $ /maintenance.html [R=302,L]

It’s as simple as that. If you want to allow more than one IP, you can just duplicate the REMOTE_HOST line as many times as you want with your new IP addresses. Upload to the root directory and you’re good to go! Good luck!

Random Posts

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

2 Comments »

  • Micah said:

    Cool tutorial!

    I have one question though, I am thinking about taking down my website for maintenance. Can I make a custom display when other people try to get on it? Like, “Website is under maintenance. Please try again later”?

    Micah

  • Micah said:

    Nevermind, figured it out

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.