What is the best way to prevent access to certain directories of a website?

How can direct access to certain directories of a website be prevented?

1- Creating and placing a file .htaccessin each directory that we want to protect, and put the following line in it:

Deny from all

2- Creating and placing a file index.phpin each directory that we want to protect, and place only the following line of code in it (which will be redirected to the website’s home page):

<?php header("Location: http://" . $_SERVER['HTTP_HOST']); ?>

3 Something else (what is it?)

+5
source share
1 answer

, -. , , .htaccess .htaccess.

, PHP $_SERVER['DOCUMENT_ROOT']. , /var/www/html, /var/www/protected_folder, Apache ( -) ( http.conf ).

, .htaccess DENY - .

TerryE, OS, Apache (, 700). , 403, , , ( 403 http.conf htaccess). , , , (, PHP include() ..), , PHP - . , ( ), reset ( , - ).

+5

All Articles