Home >Backend Development >PHP Tutorial >How to Prevent Direct PHP File Access in Apache Except for Index.php?
Denying Direct PHP File Access Except for Index.php
Protecting your PHP files from unauthorized direct access is crucial for the security of your web application. This article discusses a solution to deny access to all .php files except for index.php, ensuring that users can only access other PHP files through PHP include.
Apache Configuration
To implement this restriction, you can 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>
Update for Apache 2.4
In Apache 2.4, the access control syntax has changed. Replace the "Deny from all" directive with "Require all denied" to achieve the same effect.
The above is the detailed content of How to Prevent Direct PHP File Access in Apache Except for Index.php?. For more information, please follow other related articles on the PHP Chinese website!