Web Dev, Linux, WordPress & More

Prevent File Browsing with .htaccess

by eric on January 21st, 2007 in: LinuxOther StuffWeb Design

Need to block access to a directory on your site?

If your hosting environment runs the Apache web server, you can simply create an .htaccess file in the directory you’d like to protect and insert the following code:

Options -Indexes

For example, say you’ve created a sub-folder on your site to hold images. Without protection, a user could visit http://yoursite.com/images/ and see a directory listing of the files and folders in the images directory.

By simply creating a file with the above line and saving it as .htaccess in the images directory, users will get an error rather than a directory listing when they visit the URL.

For more info on .htaccess, visit the Apache website.

technorati tags:,

3 Responses to ' Prevent File Browsing with .htaccess '

Subscribe to comments with RSS or TrackBack to 'Prevent File Browsing with .htaccess'.

  1. fedmich said:

    March 12th, 2008 at 08:19

    Thanks, just what I needed

  2. eric a. said:

    March 12th, 2008 at 08:21

    No problem – glad it helped. 🙂

  3. Biztastic said:

    December 28th, 2008 at 10:41

    This works great thanks! great use when you haven’t got access to the server’s config file.

Leave a Reply

%d bloggers like this: