Search code examples
apache.htaccesswebserver

How to block access to a particular route in .htaccess file


I need to block access to a particular route in my web application using a .htaccess file for everyone except a list of IP's. When I try to do it myself: block all and whitelist my IP's for a particular route it looks like this:

order deny,allow
deny from all
allow from 1.1.1.1
allow from 2.2.2.2

I tried using the Location directive, but it is not allowed in .htaccess.

I do not have access to the server config file since it is a managed hosting provider.

The route I want to block is for eg: http://www.example.com/route1

Is there a way?


Solution

  • You can definitely achieve this using multiple methods.

    .htaccess files:

    <files route1>
        order deny,allow
        deny from all
        allow from my.ip.address
    </files>