1

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?

Jelle De Loecker
  • 20,999
  • 27
  • 100
  • 142

2 Answers2

1

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]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
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
anubhava
  • 761,203
  • 64
  • 569
  • 643