Using .htaccess will let you control who is able to access and view different areas of your website. Continue reading to learn how to allow site access based on an IP address.
order deny,allow deny from all # Jordan's computer allow from 22.214.171.124 # Kate's computer allow from 126.96.36.199
You may restrict access to your website so that only the IP addresses you specify can view your website. In the sample above everyone is blocked from visiting my website except for my computer (IP Address: 188.8.131.52) and my friend Kate’s computer (IP Address: 184.108.40.206). Copy the code above and replace the IP addresses that you want to give access to. Place the .htaccess at the root level of your website.
<Files CheatCodes.php> order deny,allow deny from all # Jordan's computer allow from 220.127.116.11 # Jordan's laptop allow from 18.104.22.168 </Files>
The sample above demonstrates how you can restrict access to a particular file on your website. In the sample I am limiting access to the CheatCodes.php file so that only my compter and my laptop are able to view the file. You have several options for placing the code in your .htaccess file. You can place the code in your site’s root .htaccess or create a new .htaccess in the CheatCodes.php’s directory. Remember to make sure that the file path is correct if you are placing the .htaccess outside of your file’s location.
order deny,allow deny from all # Jordan's computer allow from 22.214.171.124
This is very similar to the website access mentioned earlier in the article. Instead of placing the code shown above in your website’s root folder, you will now be creating a new .htaccess and place it in the directory that you want to limit access to. Let’s say that you have a region of your site that you wish to block access to and the region is: website.com/testing/. You will now create a new .htaccess file and place it at /testing. The permissions granted in the .htaccess will apply to all sub directories in /testing so you will not have to worry about creating subsequent .htaccess files for other folders in that directory.
You may be interested in blocking access from an IP address