Denying access to certain files on an Apache web server

This content is 20 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

Under certain circumstances, it may be necessary to deny users access to various files on a web server.

For example, some directives in an Apache .htaccess file may be considered a security risk and so access to the file may be prevented using the following directives:

<files .htaccess>
order deny,allow
deny from all
</files>

The first line limits the directive to the .htaccess file (simply change the filename to limit access to other files), whilst the remaining code sets deny to have precedence over allow, denies access from all users and then terminates the directive.

3 thoughts on “Denying access to certain files on an Apache web server

  1. I have used your code and I was now able to protect certain files from the viewer like classes file and my .htaccess file.

    Thanks Alot!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.