Home >Backend Development >PHP Tutorial >How Can .htaccess Prevent Direct Access to Specific Folders and Files?

How Can .htaccess Prevent Direct Access to Specific Folders and Files?

Barbara Streisand
Barbara StreisandOriginal
2024-12-19 17:20:10716browse

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:

  • index.php in the root folder
  • includes folder containing files included in index.php
  • submit.php in the root folder for form submission

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn