Restricting access to a website using a .htaccess file is easy. Below is a code snippet to show you how to restrict access using .htaccess. Refer to the code below, and copy + paste it into your .htaccess file. Follow these instructions.
- Create a .htaccess file in the directory you wish to protect.
- Copy the following code and paste it into your .htaccess file.
deny from all
allow from 188.8.131.52
allow from 184.108.40.206
Now that you have a .htaccess file with pre-filled code, replace the rows that say allow from with IP addresses you wish to have access to your directory. Add the IPs right after allow from.
The deny,allow is important, since you're denying access first, then allowing access. You first deny all access to your directory, then allow specific IPs through the block you've set. This is great security practice, and ensures only those you specify are able to access your directory's contents.
For additional information on working with .htaccess files, you can find documentation on the official Apache website. This resource contains a lot of useful information, and could answer some unanswered questions you may have.
Apache.org .htaccess Documentation