当您需要拒绝所有 IP 访问文件夹时,您应该将 .htaccess 放入此文件夹中,该文件夹必须包含:
Order Deny,Allow
Deny from all
Allow from 1.1.1.1
您可以在虚拟主机中执行此操作,如下例所示:
<Directory "/var/www/html/mysite/my_folder">
Order Deny,Allow
Deny from all
Allow from 1.1.1.1
</Directory>
但是,当 my_folder 及其虚拟目录不存在时,我该如何解决这个任务?
有 .htaccess,位于“mysite”文件夹(/var/www/html/mysite/.htaccess):
AddDefaultCharset utf-8
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteRule ^favicon.ico$ - [F,L]
# if directory exist, use it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if not, sent requests to index.php
#RewriteRule . index.php <-- before
RewriteRule ^([^/].*)$ /index.php/$1 [L] # <-- after