我不知道如何编写一个.htaccess文件阻止所有访问目录,除了阅读html文件,这应该是允许的和PHP文件需要authentication。 拒绝所有的访问,并允许HTML工作正常,但要求密码的PHP文件不。
这是我想出来的:
<FilesMatch ".*\.php$"> AuthName "Test area" AuthUserFile /var/www/.htpasswd AuthType Basic require valid-user </FilesMatch> <FilesMatch "\.html?$"> Order Allow,Deny Allow from All </FilesMatch> order Allow,Deny Deny from ALL
谢谢,
AC
我想通过authentication或授权,而不是两个,你需要Satisfy Any
(默认是Satisfy All
)
Order deny,allow Deny from all <FilesMatch "\.php$"> Satisfy Any AuthName "Test area" AuthUserFile /var/www/.htpasswd AuthType Basic require valid-user </FilesMatch> <FilesMatch "\.html?$"> Allow from All </FilesMatch>
注意:对于Apache> = 2.4,此方法已被弃用(请参阅新的<Require(All|None|Any)>
和Require
指令)。