Security – How to forbid access to admin URL path in Apache config by IP subnet

apache-2.2apache-2.4Security

I want to only allow a private IP range to be able to access the administrator panel on my site.

I found an article explaining how to do it for a specific directory path, such as /var/www/admin/, but not by URL. I am unable to use the exact directory path because I'm using an MVC framework that doesn't have static files I can point to.

Is it possible to do this in a virtual host configuration?

The pseudo code in my head would look something like this,

<Directory $domain/admin>
  Order allow,deny
  Allow from 192.168.1.0/24
</Directory>

Best Answer

You can use the <location> block

<Location /admin>
    Order Allow,Deny
    Deny from  all
    Allow from 192.168.1.0/24
</Location>
Related Topic