How do I restrict web access for a website or folder to only a few IPs?

To restrict web access for your enter site, you can place .htaccess file in public_html with the following directives in it:

allow from IP
deny from all

(where IP will need to be replaced with an actual IP address. You can have as many allow from IP lines as you like and the last line should be deny from all).

Example: You want to allow access to IP 12.34.56.78 and 123.100.123.100. These are just example IPs. And you want to deny access to everyone else. You can use FTP or File Manager in cPanel and create a text file with the name of .htaccess (please note the file name starts with a dot). The file will contain these three lines:

allow from 12.34.56.78
allow from 123.100.123.100
deny from all

That is all. Upload this file to public_html if you want to restrict access to entire site or if only a certain folder and files/folders under that certain folder then upload it under that. Say you want to restrict access to yourdomain.com/secret/ then you need to upload .htaccess file to public_html/secret/ folder.

The rules are read from top to bottom. If a request comes from first or second IP, they will get access. If a request to access the website comes from another IP, the third rule will match and will be denied access.

If you get Internal Server Error when you setup the rules, most probably something went wrong with file permission. The permission for .htaccess file should be 755.

Let us know if you need further assistance. 

  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

I am unable to reach my server/account/web site?

Please check this knowledgebase article if you are unable to reach your website or server: I...

Website Hacked - How to secure it?

There is a detailed article posted on our blog that explains this. Please check here: Website...

I have uploaded images in correct folder but they do not show up on website? What is hotlink protection?

This issue comes up often as a result of misconfiguration of "Hotlink Protection" in cPanel. This...

Mail not deliverable with error 454 TLS currently unavailable

This issue typically applies to Virtual Private Servers and Dedicated Servers. If email delivery...

How do I know if my email was delivered or if I missed any?

In cPanel there is a feature called Email Trace. Please login to your web hosting account's...