How to Whitelist Path in Apache Web Server


whitelist path in apache

Sometimes, you may have to allow access to a specific URL path or directory in an otherwise password protected website/portal. So let us take a look at how to whitelist path in Apache web server.

 

How to Whitelist Path in Apache Web Server

Here are the steps to whitelist path in Apache web server.

Before proceeding, please ensure you have enabled .htaccess (mod_rewrite) in your Apache web server. Here are the steps to do it:

 

Place your .htaccess file in the root document folder of your website (/var/www/html)

 

1. Open .htaccess file

Open .htaccess file using a text editor. It is generally located at /var/www/html.


$ sudo vim /var/www/html/.htaccess

 

2. Whitelist URL Path

Let’s say all pages on your website/portal are password protected/restricted and you want to allow access to all for a specific URL (e.g /api/get-data) or a directory. In that case, add the following code to your .htaccess file.

Apache 2.2


<Directory /api/get-data>
# All access controls and authentication are disabled
# in this directory
Satisfy Any
Allow from all
</Directory>

 

Apache 2.4+


<Directory /api/get-data>
# All access controls and authentication are disabled
# in this directory
Require All Granted
</Directory>

 

The above code will disable any authentication to the specified URL. You can also use the above code for a directory (e.g /downloads/)

 

Apache 2.2


<Directory /downloads/>
# All access controls and authentication are disabled
# in this directory
Satisfy Any
Allow from all
</Directory>

Apache 2.4+


<Directory /downloads/>
# All access controls and authentication are disabled
# in this directory
Require All Granted
</Directory>

 

The above code will enable access to all to the specified directory.

 

 

3. Restart Apache web server

Restart Apache web server to apply changes


$ sudo /etc/init.d/apache2 start [Debian or Ubuntu]
# sudo apachectl restart [RHEL, CentOS or Fedora]

 

 

 

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!