Home / Security / How to use Apache to deny access to certain directories

How to use Apache to deny access to certain directories

403 forbidden error, access denied
In the past, we explained how to deny access to a file or directory with the allow/deny Apache server directive. There are, however, two other ways to do it that may be more to your liking. The allow/deny directive displays the 403 Forbidden page or whatever you have in its place. This might not be the most elegant way to keep users away from something. After all, it might just make them more curious about it.

Using a redirect, you can fool the site visitor into thinking the file they are looking for never existed. This will prevent any curious hackers from trying to gain access. For this example, let’s supposed you want to deny access to the “financial” directory. Edit your .htaccess file in the parent directory and add the following redirect rule:

RedirectMatch 404 /\\.svn(/|$)

Save the file, and now every time someone tries to access that directory, they will get a 404 Not Found Error rather than the 403 Forbidden one. With some simple line, you have made your private directory a little more hidden.

Check Also

Uk data center

Professional Data Centres In The UK

A professional data centre is a location in which various pieces of hardware are located …