Blocking specific file extension with htaccess?

六眼飞鱼酱① 提交于 2019-12-22 17:57:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!