Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent access to files in a certain folder

Tags:

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?

like image 952
Bv202 Avatar asked Feb 18 '11 20:02

Bv202


People also ask

How do I prevent others from accessing my files?

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.

Can you restrict access to a folder within a shared drive?

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.


2 Answers

Add this to the .htaccess file:

order deny,allow deny from all 
like image 118
ChrisJ Avatar answered Oct 03 '22 05:10

ChrisJ


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.

like image 36
kojow7 Avatar answered Oct 03 '22 03:10

kojow7