Sometimes, you may need to allow access to specific subfolder or subdirectory on your website but you are unable to do it because you don’t have access to server config files. In that case you can easily do it using .htaccess file in Apache server. .htaccess allows you to modify server configuration without actually accessing config file. Let us look at how to allow access to subfolder using .htaccess.
Allow Access to Subfolder using .htaccess
Here are the steps to allow access to subfolder using .htaccess. Before you proceed please ensure that you have enabled .htaccess (mod_rewrite) for your Apache web server. Here’s how to do it:
Place your .htaccess file in the root document folder of your website (/var/www/html).
1. Add .htaccess file to sub folder
Navigate to your subfolder (e.g/var/www/html/subfolder)
$ cd /var/www/html/subfolder
Create another .htaccess file at that location.
$ sudo vim /var/www/html/subfolder/.htaccess
Now you will have 2 .htaccess files, one at the document root (/var/www/html) and another in the subfolder (/var/www/html/subfolder)
2. Update .htaccess file in subfolder
Add the following lines to the .htaccess file in subfolder
Allow From All Satisfy Any
Save and close the file
3. Restart Apache Server
Restart Apache web server to apply changes
$ sudo /etc/init.d/apache2 start [Debian or Ubuntu] # sudo apachectl restart [RHEL, CentOS or Fedora]
That’s it! The settings mentioned in .htaccess file in subfolder will override server config and allow access to all.