我正在尝试使用AuthUserFile限制访问我的网站,但根路径除外。
SetEnvIf Request_URI "^/$" allow_access=true
Order Deny,Allow
Deny from all
Allow from env=allow_access
然而,当robots.txt等文件也受到保护时,我遇到了一个问题。
出于某种原因,以下指令不有效。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* - [E=allow_access]
Order Deny,Allow
Deny from all
Allow from env=allow_access
有没有办法限制访问/ any / path / here /除了主页(/)和物理上存在的文件,例如robots.txt和favicon.ico?
提前感谢您的帮助!
答案 0 :(得分:0)
这有点棘手,但mod_rewrite
和mod_setenvif
的这个组合有效:
RewriteEngine on
# if file or directory doesn't exist then forward to /deny
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ /deny [L]
# set env variable deny_access if URI is /deny
SetEnvIf Request_URI "^/deny$" deny_access
# block access if env variable deny_access is set
Order Allow,Deny
Allow from all
Deny from env=deny_access
答案 1 :(得分:0)
<If "-f %{REQUEST_FILENAME}">
SetEnv allow_access
</If>
Order Deny,Allow
Deny from all
Allow from env=allow_access