.htaccess拒绝访问除一个文件以外的所有文件

时间:2010-08-04 16:17:27

标签: .htaccess

除一个文件外,如何拒绝访问完整的文件夹和子文件夹? 该文件是:toon.php并驻留在同一文件夹中。

7 个答案:

答案 0 :(得分:29)

Order Allow,Deny
<FilesMatch "^toon\.php$">
Allow from all
</FilesMatch>

这可能是你能获得的最有效率。

答案 1 :(得分:10)

AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic
AuthUserFile .htpasswd
require valid-user


<Files "toon.php">
Allow from all
Satisfy Any

</Files>

适合我。不要忘记配置.htpasswd文件。

答案 2 :(得分:6)

Deny From All
<FilesMatch "^toon\.php$">
Allow From All
</FilesMatch>

为我工作......

答案 3 :(得分:5)

您可能希望使用<Directory><Files>指令。您可以在这里查看文档:

http://httpd.apache.org/docs/1.3/mod/core.html#directory

http://httpd.apache.org/docs/1.3/mod/core.html#files

简而言之,你想要这样的东西:

<Directory /folder/without/access >
     Order Deny,Allow
     Deny from All
</Directory>

<Files "filename">
     Order Deny,Allow
     Allow from All
</Files>

答案 4 :(得分:2)

如果像我一样,您正在寻找在整个网站/文件夹上进行身份验证的方法,除了单个文件,您会发现此方法运行良好:

#allows a single uri through the .htaccess password protection
SetEnvIf Request_URI "/testing_uri$" test_uri

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/your/.htpasswd
AuthGroupFile /
Require valid-user

#Allow valid-user
Deny from all
Allow from env=test_uri
Satisfy any

示例摘自:this site

答案 5 :(得分:2)

将以下规则添加到root

中的htaccess文件中
RewriteEngine on


RewriteRule !toon\.php$ - [F]

这将拒绝访问除 toon.php 以外的所有文件和文件夹。

答案 6 :(得分:0)

WordPress 管理员中有一种相关情况,您可能想限制对特定IP的访问,但保留对插件使用的某些特定文件的访问:

## /wp-admin/.htaccess ##
Deny from all
allow from 88.222.123.88 #Home 
allow from 88.111.211.77 #Office

<Files "admin-ajax.php">
     Allow from All
</Files>
相关问题