All HowTo's Cybersecurity Web Servers

Restricting access to Apache with htaccess

The .htaccess file can restrict access to web browsers to specific things. I’ve written about this (on this blog) previously. However, here i talk about file types.

The snippets below are (or can be) the entire contents of the .htaccess file.

Prevent access to bash files that shouldn’t be in the root (document root):

<Files ~ "\.sh$">
Order deny,allow
Deny from all
</Files>

If you need to have bash scripts accessible via Apache, consider putting them in a directory perhaps called “/private” and we can then restrict that to the location:

Order allow,deny
Deny from all
Allow from 172.0.0.1

Leave a Reply

Your email address will not be published. Required fields are marked *