Home >Backend Development >PHP Tutorial >How to Restrict Direct Access to PHP Files (Except Index.php)?
Preventing Direct Access to .php Files
Securing .php files from direct access is crucial for website protection. This article addresses the need to restrict access to all .php files except index.php, ensuring that files are only accessed through PHP include.
Solution:
To deny direct access to all .php files except index.php, follow these steps:
Order Deny,Allow Deny from all Allow from 127.0.0.1 <Files /index.php> Order Allow,Deny Allow from all </Files>
Explanation:
Additional Considerations:
<FilesMatch ".*\.(css|js)$"> Order Allow,Deny Allow from all </FilesMatch>
Caution:
Update for Apache 2.4:
For Apache 2.4, use Require all denied instead of Deny from all in the first directive.
The above is the detailed content of How to Restrict Direct Access to PHP Files (Except Index.php)?. For more information, please follow other related articles on the PHP Chinese website!