I have a folder with a lot of .php
files. I would like to deny access to them (using .htaccess
). I know an option is to move this folder outside public_html
, but this is not possible in this situation.
Is is possible to block access to a whole folder?
Select properties, and then select the "security" tab. You will then see the security options for the folder you chose. Click on the "to change permissions, click edit" button underneath the "Groups or User Names" box. A new box will pop-up that gives you access to control the permissions for Groups and Users.
Restrict access to that folder so that only users on the distribution list can access it. You can make this a little more complex by changing the tiers of control over the folder. i. Full restriction/access – only those on the list can open the folder and once they're in they can do anything they want.
Add this to the .htaccess
file:
order deny,allow deny from all
Apache 2.4 now uses a different way to do this so the method that works for Apache 2.2 will not work. See below for the method that will work for Apache 2.4. Place this in your Apache .htaccess file or better yet in a <Directory>
directive in the Apache .conf file for your site.
Using .htaccess:
If using Apache 2.2:
order deny,allow deny from all
If using Apache 2.4 use:
Require all denied
Using Apache Configuration files:
Instead of using a .htaccess file, it is usually preferred to place the configuration directly in your Apache .conf file as follows:
<Directory "/var/www/mysite"> Require all denied </Directory>
Or if using a virtual host:
<VirtualHost *:80> ### Other configuration here ### <Directory "/var/www/mysite"> Require all denied </Directory> ### Other configuration here ### </VirtualHost>
Of course the above configurations are examples, and you will need to adjust according to your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With