Web Design Firm - MOR Designs - Home
endcap graphic
 

HOW TO PROTECT DIRECTORIES
THAT HAVE NO INDEX.HTML FILE

Q&D Folder Restriction (security)

By John Bates
©
2003
http://www.mordesigns.com

Applicable to: Systems utilizing Apache

There are a few solutions to the problem of preventing access to errant visitors viewing folders (and their content) that are without an index file.

The solution below is one that I've found to be elegant and easy to implement. In addition, you can author a nice "error" message if you wish, AND, it can save some considerable space and time.

It is derived from the Apache DirectoryIndex function.

****

1.) Add the following line to your .htaccess file:

DirectoryIndex index.shtml index.htm index.html index.cgi index.php /restrict.html

2.) You may place any file name, that your particular system has been set up to default to, in that line (that you know are absent from a folder(s) that you don't want to be viewable).

* See Notes Below

3.) Next, create a "restrict.html" file, in the same folder as the .htaccess file (unless you change the path in the line above), and populate it with whatever message you want an errant visitor to see.... such as:

Sorry! You are not authorized to view this directory's contents. Contact: webmaster@yoursite.com

4.) What the above all does, is: When a user types in an address to a folder that does not contain one of the files you specified in the .htaccess file line, or, specifically types in one of the files specified (which aren't there), it will redirect them to the restrict.html file. If the user typed in a /folder/filename that IS there, it will of course be rendered.

****

* Notes:

By "any file name, that your particular system has been set up to default to", I mean that, our esteemed system administrators most likely have set up our OS to look for a default file name(s), in a particular order, in the case that no filename was typed in the URL (such as your URL without the "index.htm" appended - http://www.yourdomain.com/).

For example, the order might be:

index.htm -> index.html -> default.htm -> index.shtml

So then:

User types in "www.yourdomain.com/fred/" ->
System looks for /fred/index.htm
If the system finds it, it gets rendered in the users browser ->
If the system doesn't find it, it next looks for /fred/index.html
If the system finds it, it gets rendered in the users browser ->
If the system doesn't find it, it next looks for /fred/default.htm
If the system finds it, it gets rendered in the users browser ->
If the system doesn't find it, it next looks for /fred/index.shtml

And so on... until it either finds one of it's defaulted filenames - or - finds none of it's defaulted filenames and then either presents a 404 error page - or - displays the contents of the /fred/ folder for all the world to see.

Addendum:

Use the tutorial above, and just make the restrict.html file like your home page, except replace the body content with the "Sorry, you are not authorized..." message. This way, folks will still have all the navigation structure that you have in your home page.

As well, this way you won't have duplicate "site map" pages.

Make sure to use full URL's rather than paths in any links/images/etc, though.

****

We hope you find this helpful.

****

You may re-publish this article as long as you include the following paragraph and as long as you link to the following URL:

Q&D Folder Restriction (security)

By John Bates
© 2003

John Bates is the owner of MOR Designs. He is a Super Moderator at the IHelpYou Forums as well as an administrator of the WebSavvy Smart Search! Directory.

For more articles by John and others please visit: http://www.mordesigns.com

 
Site Navigation
Home
Order
Pricing Schedule
spacer graphic
Consultation
Web Site Goals
Web Design Process
spacer graphic
Presence Web Site
eCommerce Web Site
spacer graphic
Search Engine Optimization
Web Site Marketing
spacer graphic
Web Site Hosting
spacer graphic
About Us
Contact Us
Privacy Policy
Legalese
Site Map
MOR Designs
3689 Lake Grove Drive
Yorba Linda, CA 92886

714-463-4119
Web Design 101
Here, we dedicate a section of our site containing useful, informative articles, guest columns, pointers, & links to tools you can use to better your web design skills!
Web Design 101
SE Optimization
Learn the current methods all the pros use to achieve high search engine rankings. We only discuss ethical optimization techniques. Tips, tools and articles.
SEO Tips
EZ eCommerce
eCommerce is easier than you think! We've put together a simple three-step plan that tells you the how's, what's and why's. Click the button below and you'll be selling online in no time.
EZ eCommerce

|| Home | Order | Pricing || Consultation | Goals | Design Process ||
||
Presence | eCommerce || Optimization | Marketing || Hosting ||
||
About Us | Contact Us | Privacy | Legalese | Site Map | Webmaster ||
Copyright © 1996-2007 MOR Designs. All Rights Reserved.

MOR Designs - Serving you since February, 1996!