Restrict access by IP Print

  • 29

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 75.133.222.223
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 123.45.2.1 to 123.45.2.254

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.

Was this answer helpful?

« Back