Control access to files at directory level Print

  • 0

.htaccess is most often used to restrict or deny access to individual files and folders. A typical example would be an "includes" folder. Your site's pages can call these included scripts all they like, but you don't want users accessing these files directly, over the web. In that case you would drop an .htaccess file in the includes folder with content something like this.

# no one gets in here!
deny from all



which would deny ALL direct access to ANY files in that folder. You can be more specific with your conditions, for instance limiting access to a particular IP range, here’s a handy top-level rule for a local test server.

# no nasty hackers in here!
order deny,allow
deny from all
allow from 192.168.0.0/24



# this would do the same.
allow from 192.168.0



Generally these sorts of requests would bounce off your firewall anyway, but on a live server they become useful for filtering out undesirable IP blocks, known risks, lots of things.

Sometimes, you will only want to ban one IP, perhaps some persistent robot that doesn't play by the rules.

# someone else giving the ruskies a bad name.
order allow,deny
deny from 83.222.23.219
allow from all



There you go. Pretty easy right.


Was this answer helpful?

« Back