Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing only localhost to access a folder where all inclusive php files exist

Tags:

php

.htaccess

We all have php files like 'connect_db.php' for include purposes only.

Suppose I have all those inclusive .php files in "www/html/INC"

And I have index.php

I want index.php accessible from browser to everyone, but I want to prevent users' direct access to "www/html/INC" folder. (e.g. when type in the browser 'www.domain.com/INC/' -> 404 error etc)

How do I achieve this?

Preferrably using .htaccess file in the root directory please.

like image 577
user706087 Avatar asked Jun 07 '11 11:06

user706087


1 Answers

Google searches have brought me here so I figured I'd post what I found in the apache docs today. I'm not positive what versions of apache it is available in, but do a search for your version to verify.

Now you can just use Require local. I'd recommend putting an .htaccess in the folder that you want to restrict access to with just that line. However, if you must do it in the root directory then here's what it would be:

<Directory "www/html/INC">
    Require local
</Directory>
like image 125
nickell Avatar answered Oct 11 '22 14:10

nickell