问题
I'm trying to deny access to a certain uri, namely /admin/
and have tried this .htaccess file:
SetEnvIf Request_URI !^/admin/ not_admin_uri
Order deny,allow
Deny from all
allow from 356.244.33.
allow from env=not_admin_uri
This works for the example IP range, but not for the "not_admin_uri" part.
What's going wrong here?
回答1:
To negate a match you cannot place !
in the SetEnvIf
directive. You need to use negative lookahead like this:
SetEnvIf Request_URI ^/(?!admin/) not_admin_uri
回答2:
Maybe try using a rewrite rule. If not from your IP then block access.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.
RewriteRule ^admin/? - [F,L]
来源:https://stackoverflow.com/questions/29014348/deny-access-to-uri