在.htaccess中阻止所有子目录级别的ip访问?

时间:2011-11-03 23:07:17

标签: php apache .htaccess restrict

我使用WHM,我需要在public_html工作中使用.htaccess,不仅要将子文件夹设置为public_html,还要设置所有子文件夹,等等。从root开始的整个文件夹树可能吗?

e.g。

我在这里存储htaccess public_html\.htaccess 这个文件夹也不应该受到影响。 public_html\myfolder\images\thimbnails\red\

如果这不起作用,我可以在apache.config中使用htaccess的相同命令吗?

规则是

ErrorDocument 403 http://google.com
Order Deny,Allow
Deny from all
Allow from 11.22.33.44



Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

1 个答案:

答案 0 :(得分:0)

.htaccess文件中的设置将由所有子文件夹继承。如果您希望特定子文件夹不受影响,则需要在其中放置.htaccess文件以覆盖父htaccess的默认设置。

因此,如果您拒绝public_html / .htaccess中的特定IP地址,并且您希望允许它看到public_html / myfolder / images / thumbnails / red,那么您需要在该文件夹中放置.htaccess以允许所有或允许被阻止的IP。