Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Allow Only One IP Address with .htaccess

Deny everyone except one IP address from your site or a folder.

SSL and Security2 min read3 steps

The rule

Say you want to allow only the IP address 1.2.3.4. Add this to the .htaccess file of your site, or of the folder you want to protect (Apache 2.4):

Require ip 1.2.3.4

Everyone else gets a 403 Forbidden page.

For older servers (Apache 2.2 style)

Order Deny,Allow
Deny from All
Allow from 1.2.3.4
  • Order Deny,Allow sets the order in which the rules are processed.
  • Deny from All blocks every address first.
  • Allow from 1.2.3.4 then lets your address in.
Note: If your server runs Apache 2.4, use Require ip. The old Order, Allow and Deny lines work only when the compatibility module is loaded. Do not mix both styles in one file.

Allow more than one address

Require ip 1.2.3.4 5.6.7.8

You can also use a range, for example Require ip 1.2.3.0/24.

Test and undo

  1. Save the file and open the site from the allowed IP address. It should load.
  2. Open it from another network. It should show a 403 error.
  3. To undo, delete the lines you added.
Warning: Check your own IP address before you save. If you use a wrong address, you lock yourself out. If your IP changes often, this method is not the best for you.

Quick recap

  • Require ip allows only the listed addresses (Apache 2.4).
  • Everyone else gets a 403 error.
  • Make sure your own IP is right before you save.