使用.htaccess禁用目录(包括所有子目录)中的PHP

使用.htaccess禁用目录(包括所有子目录)中的PHP

我正在建立一个允许人们上传文件,html页面等的网站......现在我遇到了问题。我有这样的目录结构:


-/USERS

    -/DEMO1

    -/DEMO2

    -/DEMO3

    -/etc... (every user has his own direcory here)

-index.php

-control_panel.php

-.htaccess

现在我想禁用PHP,但在/ USERS内的direcories和子目录中启用服务器端包含


可以这样做(以及如何:))?提前致谢。


顺便说一下,我使用的是WAMP服务器


长风秋雁
浏览 936回答 3
3回答

MMMHUHU

尝试禁用.htaccess文件中的engine选项:php_flag engine off

慕哥6287543

要禁用对子目录的所有访问(最安全),请使用:<Directory&nbsp;full-path-to/USERS> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order&nbsp;Deny,Allow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny&nbsp;from&nbsp;All&nbsp;</Directory>如果您只想阻止直接提供PHP文件,请执行以下操作:1 - 确保您知道服务器识别为PHP的文件扩展名(并且不允许人们在htaccess中覆盖)。我的一台服务器设置为:#&nbsp;Example&nbsp;of&nbsp;existing&nbsp;recognized&nbsp;extenstions:AddType&nbsp;application/x-httpd-php&nbsp;.php&nbsp;.phtml&nbsp;.php32 - 基于扩展,将正则表达式添加到FilesMatch(或LocationMatch)&nbsp;<Directory&nbsp;full-path-to/USERS> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FilesMatch&nbsp;"(?i)\.(php|php3?|phtml)$"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order&nbsp;Deny,Allow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny&nbsp;from&nbsp;All&nbsp;&nbsp;&nbsp;&nbsp;</FilesMatch> &nbsp;</Directory>或者使用Location来匹配php文件(我更喜欢上面的文件方法)<LocationMatch&nbsp;"/USERS/.*(?i)\.(php3?|phtml)$"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order&nbsp;Deny,Allow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny&nbsp;from&nbsp;All</LocationMatch>

大话西游666

如果你正在使用mod_php,你可以把(在/ USERS中的.htaccess或者在USERS目录的httpd.conf中)RemoveHandler&nbsp;.php要么RemoveType&nbsp;.php(取决于是否使用AddHandler或AddType启用PHP)从另一个目录运行的PHP文件仍然可以包含/ USERS中的文件(假设没有open_basedir限制),因为这不通过Apache。如果使用apache访问php文件,它将作为纯文本服务器。编辑Lance Rushing的拒绝访问文件的解决方案可能更好
打开App,查看更多内容
随时随地看视频慕课网APP