Restrict access by IP

WARNING:  Backup your current .htaccess file if you have one so you can quickly revert in case things go bad, like typos or invalid characters.
Add the following lines to your .htaccess file in your root directory, or the directory that you wish to protect. Adding to a directory will protect that directory and all directories below it.

# start block rules
Order Deny,Allow
Deny from all
Allow from
Allow from 123.45.2
# end block rules

Please note: IPs listed above are example IP addresses, not real ones!  Use your IP instead.
To find out what your IP is, visit this link: What is your IP?

Add this to your .htaccess file, or create one if you do not have one with your favorite text editor, upload the file to the server into the directory you wish to protect.  This could be the site's root directory if you want to limit access to the entire site, or to a specific directory such as wp-admin.

This will allow only the listed ip(s) to access your site, while blocking the entire world. You can add as many as you wish. Note the 2nd example, 123.45.2 – this will block the full class C, from to

Again, test it to ensure this is the effect you want. At any time, you can remove the .htaccess file, or rename it to, example, off.htaccess and it will disable any rules you have specified.
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Domain redirect

So you bought another domain name that matches one you currently have.  You shouldn’t...

restrict by IP or password

I find myself tired of having to answer the pop up authentication box to view my control panel...

rewrite base

Top directories can break functionality on sub directories. Case in point:Scenario: WordPress...

rewrite non SSL to SSL

Want to force users to use SSL on your site?Add this code to the top of your .htaccess file, edit...

Traffic source redirect

Need to redirect source traffic to another domain?  Well, if you can’t modify the link...