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

时间:2021-02-23 15:20:33

How can I deny access to a complete folder and sub-folders, with the exception of one file? That file is: toon.php and resides in the same folder.

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

7 个解决方案

#1


26  

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

That is probably the most efficient that you can get.

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

#2


8  

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


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

</Files>

Works for me. Dont' forget to configure the .htpasswd file.

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

#3


6  

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

Worked for me...

为我工作......

#4


4  

You may want to use the <Directory> and <Files> directives. You can look at the documentation here:

您可能希望使用 指令。你可以在这里查看文档:

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

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

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

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

In short, you want something like this:

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

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

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

#5


2  

If, like me, you're looking for a way to have authentication on an entire site/folder except for a single file, you will find that this method is working very well:

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

#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

Example taken from : this site

示例摘自:此站点

#6


2  

Add the following rule to htaccess file in root

将以下规则添加到root中的htaccess文件中

RewriteEngine on


RewriteRule !toon\.php$ - [F]

This will deny access to all files and folders except toon.php .

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

#7


0  

There is a related scenario in WordPress admin where you may want to limit the access to specific IPs, but leave access for some specific files used by plugins:

在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>

#1


26  

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

That is probably the most efficient that you can get.

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

#2


8  

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


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

</Files>

Works for me. Dont' forget to configure the .htpasswd file.

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

#3


6  

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

Worked for me...

为我工作......

#4


4  

You may want to use the <Directory> and <Files> directives. You can look at the documentation here:

您可能希望使用 指令。你可以在这里查看文档:

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

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

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

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

In short, you want something like this:

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

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

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

#5


2  

If, like me, you're looking for a way to have authentication on an entire site/folder except for a single file, you will find that this method is working very well:

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

#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

Example taken from : this site

示例摘自:此站点

#6


2  

Add the following rule to htaccess file in root

将以下规则添加到root中的htaccess文件中

RewriteEngine on


RewriteRule !toon\.php$ - [F]

This will deny access to all files and folders except toon.php .

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

#7


0  

There is a related scenario in WordPress admin where you may want to limit the access to specific IPs, but leave access for some specific files used by plugins:

在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>