Search code examples
apache.htaccesssetenvif

Deny access to URI


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?


Solution

  • 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