问题
I am using this code to send all the request to a single php file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) myfile.php?id=$1 [QSA,L]
But now I want to also block direct access to myfile.php and other phps. I don't want the php files to open directly via browser, but they must work for includes and such.
How can I do this?
回答1:
Maybe this will help:
RewriteCond %{REQUEST_URI} !(.*).php$ [NC]
RewriteRule ^.* - [F,L]
Several nice examples are here: Apache wiki: RewriteCond
回答2:
You can block files with the Files directive. To block files ending in .inc, do this:
<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>
来源:https://stackoverflow.com/questions/6501575/blocking-specific-file-extension-with-htaccess