Limit certain ip to access website with .htaccess

Many friends ask me to limit only certain ip are allow to access their website. To limit specific ip to access website is easy with .htaccess. Just follow the steps below and you will be able to set your website to be view by specific ip:-
- Create a file and name it .htaccess with the content below:-
order deny,allow deny from all allow from 888.888.888.888
Please change 888.888.888.888 to the ip you want to allow.
- Once the file is created, put it at your root directory. (This will be in http://www.yourdomain.com/.htaccess)
- Done! Now your website is can only be access by the ip you set!
- If you want to allow multiple ip address to access your website, just create another record of ip like below:-
order deny,allow deny from all allow from 888.888.888.888 allow from 999.999.999.999 allow from 000.000.000.000
Tags: .htaccess, apache .htaccess, apache .htaccess block ip, apache .htaccess block user, htaccess limit ip access, limit ip access, limit ip access website
Posted at January 16th, 2007 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)



January 8th, 2009 at 12:06 am
Very useful – thanks. How would you limit certain ip to certain folders? I don’t want to limit access to the whole site, just certain folders.
June 26th, 2009 at 11:21 pm
Haydon,
In case you haven’t gotten your answer yet….. just put the .htaccess file in any folder you need to protect. I believe it will work recursively, any file or folder contained within the folder with the .htaccess will follow the same rules.
Hope this helps.
October 19th, 2009 at 5:21 am
thank you for this…
January 28th, 2010 at 5:38 pm
thanks this gives me a headstart. what i want to do is to give access only for a range of ip address (like from 50 to 100 only) what should i do then?
January 29th, 2010 at 9:24 pm
hmmm from wat i know, u can only block a range but not in the same range.
anyone know the tricks?