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
  • Windows Run as to let a legacy program run in XP limited user mode Several months back I had to figure out a way to get Create a card gold (5.0?) run on an XP system. The only real problem was that I had setup the account with limited user privileges (shared machine, several users, all with limited account priviliges.) But, somehow the program......
  • Using .htaccess to ALLOW directory browsing By default the apache install for most sites now restricts directory browsing. It's a good idea, you don't want just ANYTHING to be browsable on a web server, but there comes a time that it makes life easier for a directory (or tree of directories) to be browsable without having......
  • Backing up and restoring MySQL databases In the past few days I've been working on an automated backup system for both my site databases and a few others. I thought I'd take a bit to go through what I've done. It's really simple, but I suspect there are some that either don't realise it's this simple,......
Blog Traffic Exchange Related Websites
  • How To Adjust Web Hosting Devoid Of Downtime I am positive that if you are visiting this page, you will be interested in change web hosting. Changing from a single internet hosting provider to a different can cause downtime if you do not have the necessary abilities and experience. Here is a step by step guide to aid......
  • Templates For E-Commerce Web Hosting Developing a expert website may be difficult. E-commerce internet style is truly a complex animal. To cut development time, numerous web hosting organizations start offering web hosting templates or hosting with templates. Whether or not you are looking for a easy internet website or a functional e-commerce website, the chances......
  • Twenty Steps To Getting Your Blog Setup For Quick Traffic With blogs showing up every seconds, it’s a complete mystery to many bloggers how to build their blog site to stand out from the crowd. It’s simple really. People prefer to read good content that is instantly actionable. These actionable tips should certainly benefit your blog site making it feel......
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