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

share on:
restrict access to website or directory by ip

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

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

You can also make use of Keyclock in your application for authentication. please check the 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.


About .htaccess: .htaccess is a configuration file for use on web servers running the Apache Web Server software.These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer.

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.

You can add following directive in your .htaccess file to restrict access to the directory based on the ip addresses.

<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. Don't forget to leave the feedback. Have a great day. :)

Leave a Response

share on: