Home >Backend Development >PHP Tutorial >How Can .htaccess Prevent Direct Access to Specific Folders and Files?
Restricting Direct Access to Folders and Files Using .htaccess
You have a website with the following structure:
You want to prevent users from directly accessing files in the includes folder or submit.php, while allowing index.php to include these files.
The solution is to create a .htaccess file in the includes folder with the following content:
deny from all
This code will restrict direct access to any files in the includes folder. When a user tries to access a file in the folder, they will be denied access.
To prevent direct access to submit.php, you can create another .htaccess file in the root folder with the following content:
deny from all
This code will restrict direct access to submit.php. When a user tries to access submit.php, they will be denied access.
The above is the detailed content of How Can .htaccess Prevent Direct Access to Specific Folders and Files?. For more information, please follow other related articles on the PHP Chinese website!