How to restrict access to website or directory by using .htaccess.

share on:
restrict access to website or directory by ip

We are often required to restrict access to website using virtual host configurations or by using .htaccess.

In this tutorial, we will see how easy it is to restrict access to website or a particular directory using .htaccess.

To learn about Nginx and apache url rewrite for wordpress, please check this link.

This article is related to .htaccess configuration used in apache version 2.4+ only. Also make sure use of .htaccess is allowed in virtualhost configuration and  AllowOverride all is present in config.


To restrict access to website or directory using .htaccess, all you need to do is place an .htaccess in your document root or in directory you want to apply restrictions to respectively.

<RequireAny> 
Require ip 10.10.11.11
Require ip 10.10.11.12
Require ip 10.10.11.13
Require ip 10.10.11.14
</RequireAny>

This will restrict the access to website from these ips mentioned in the list only.

Hope this will be helpful for some. Thanks and have a great day. 🙂


share on:
engy

engy

Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Good Day. :)

Leave a Response

share on: