Ever want to prevent users from accessing specific areas of your site?  You can do so through software; for instance, WordPress has a login mechanism for users.  But let’s say that you want to prevent the general public from accessing a specific area of the site regardless of being logged in.  You can do this using the .htaccess file.

In a nutshell, a .htaccess file is a configuration file that affects the folder it resides in and any subfolders below the file.

For example, I have a folder structure like this:

  • Root
    • FolderA
      • FolderA1
      • FolderA2
    • FolderB

If I want to block off FolderA2 from general public access.  To do this, I add a new file to /Root/FolderA/FolderA2 and title it “.htaaccess”.  The file is a plain text file and inside, I type the following:

Order deny,allow
Deny from all

Next time I access the any files in FolderA2 through my web browser, I see something like this:

post-htaccess-forbidden

Keep in mind that you can place one .htaccess file in each folder.  Of course, .htaccess files that are in child folders take precedence over parent folders.