Protecting access to web directories with htaccess



Okay, in an earlier article I was looking at uses of Google that might reveal things you don’t want revealed about your website. Maybe a test directory that you don’t want to be spidered. I want to say that it’s not possible to keep it hidden just by NOT linking to it. That’s what some will suggest, the argument goes along these lines “spiders just follow links, so don’t link to a directory or document you don’t want the web spiders to see.” Spidering bots seem to be a bit more resourceful though, I’ve seen files and folders that I can’t imagine were linked to being picked up in a web search, so how do we prevent that?

For that matter what about the people that might get lucky and guess our testing directory? There’s one answer that can solve both of these problems. It’s done using the .htaccess file.

You’re going to probably need to log into the command shell on your webserver unless your host has a control panel to deal with this. Password protect directories is what we’re going to do.

You need to create a file in the directory that you want to protect, let’s say it’s yourdomain.com/test and the path is /var/www/html/test
AuthUserFile /var/www/html/test/.htpasswd
AuthName protectedtest
AuthType Basic

require valid-user

Ok, this is good save and close, make sure that it is called .htaccess (a period in front of htaccess)

Then make sure you’re in the directory to be protected…

type the following to create the .htpasswd file and setup the first user

htpasswd -c .htpasswd testfolderuser

future users can be added by the following

htpasswd .htpasswd secondtestuser

After each of the above commands you will be prompted for a password for the user and then prompted to confirm it and everything should be set. There are some warnings to go along with this. Don’t put your .htpasswd file in a folder that can be viewed without permission. It’s USUALLY advisable to put it outside of the web-tree somewhere. If you do that, make sure to 1) specify the absolute path in the .htaccess file so .htaccess can find your password list. and 2) when running htpasswd, make sure to specify the absolute path to the .htpasswd file you are changing.

It is possible to have multiple password protected directories using either the same file of usernames and passwords, or a different set of usernames and passwords by using a different filename.

Related Posts

Blog Traffic Exchange Related Posts
  • Virtual Server on Apache to listen on an alternate port In the last few days, I had to set up something a bit unusual with apache. Basically the goal was to have apache listen for connections on two different ports (the standard port 80 and an alternate port 85). The problem was that I wanted different content at each port.......
  • Custom Error Pages with .htaccess Ok, we've looked at controlling access to directories with .htaccess, but there are other neat tricks we can do that can add a bit of polish to your site. One that I've implemented lately is a custom error page. Now, we've all done this, clicked on a link and get......
  • Open Source Web templates One of the things that I've really not looked at until lately is the use of open source web templates. I don't know why but I've never really paid much attention to the thought of templates outside of those for a cms platform like wordpress or ezcontents, etc. However, recently......
Blog Traffic Exchange Related Websites
  • Useful Applications on the Go If you're a geek like me and you carry around a USB drive on your keychain, you might be looking for some useful utilities to keep on your drive.  First and foremost you need to protect your portable drive with encryption.  Information can fall into the wrong hands if the......
  • HostGator Coupon Code - It Works We know that HostGator is one of the famous web hosting service in the world and it is one of the oldest service provider in the market too. With over 12K servers managed world wide, they have helped people to register over 5000K domain names. They are very much proud......
  • Affiliate Programmes Explained People are often confused by affiliate programmes. This article aims to remove that confusion and make the whole area of affiliate marketing clear and simple. In simple terms, affiliate programmes are a way to get other people to promote your products and services in return for a commission payment.......
www.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site