Deny direct access to PHP files using htaccess

This can be helpful if you have a lot of php include files and want to deny direct access to those files.

# forbid direct .php execution #
RewriteCond     %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php - [F,L]

You can use the same htaccess directives to forbid other files from direct access. You only need to change the extension. For example:

# forbid direct .txt execution #
RewriteCond     %{THE_REQUEST} (.*)\.txt
RewriteRule ^(.*)\.txt - [F,L]
- Posted by Ana to Apache