URL rewriting could be used to map a URL to .php files. The following rules can identify whether a .php request was made directly or it was re-written. It forbids the request in the first case:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ]
RewriteRule \.php$ - [F]
RewriteRule test index.php
These rules will forbid all requests that end with .php
. However, URLs such as /
(which fires index.php), /test
(which rewrites to index.php) and /test?f=index.php
(which contains index.php in querystring) are still allowed.
THE_REQUEST
contains the full HTTP request line sent by the browser to the server (e.g., GET /index.php?foo=bar HTTP/1.1
)