Deny access to URI

只谈情不闲聊 提交于 2020-01-05 09:36:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!