.htaccess - Limit website access by IP

I've been asked many times how to limit website access by allowable IP's. This is fairly simple to accomplish with .htaccess and very useful for blocking web vagrants to allowing you to make updates to a website while redirecting all other IP's to a maintenance page. Simply follow the steps below:

  1. Create a file and name it .htaccess. Paste the code into it. Replace 255.255.255.255 with you IP address. (If you don't know it, you can get it here: WhatsMyIP)
  2. order deny,allow
    deny from all
    allow from 255.255.255.255 
    
  3. Once the file is created, put it in the root directory. That's it!

3 comments for .htaccess - Limit website access by IP

Chris Belcore's picture

Exactly what I needed thanks....

Exactly what I needed thanks.

Lebenka's picture

So if i change ip in htaccess...

So if i change ip in htaccess and then my provider changes it i'll have no access to my site?

Alkemist's picture

Hi, I am trying to build my...

Hi, I am trying to build my website and I would like to use .htaccess to limit the number of times each IP address is able to access certain pages. How can I do that? I found online almost nothing about this, but I noticed some websites use this kind of restriction. I imagine there must be a way of keeping track of each IP address that links to my website and then limiting the number of times each of them can link. If they access more than the allowed number of times, they would be redirected to an error page. Any suggestion would be greatly appreciated. Thanks.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.