• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

.htaccess error pages

BTW, where is the .htaccess file located? Also, what is the .htpassword file for? Suppose I have a folder under the root named "/test", now how do I password protect it using .htaccess and .htpassword?
 
Just use .htaccess. If you put in under /test, then everything in test (including directories) will fall under that password protection.

Make sure your host has enabled overrides though, otherwise you wont be able to do anything :)
 
Sure, so I don't need .htpasswd but what would be the syntax of the .htaccess file to protect "/test" and where should I upload (which folder) it thereafter?
 
Ok, I think you may be a little confused, but let me try to help you out. First off, your .htaccess should be something like this:

AuthUserFile /path_to_your/.htpasswd
AuthName A_Cool_Name
AuthType Basic

<limit get post put>
require valid-user
</limit>

Now, you may be asking...what the heck is .htpasswd. Well, this is something _you_ dont modify, a program does that for you.

Run this command:
htpasswd /path_to_your/.htpasswd new_user

If you are doing it for this first time do:

htpasswd -c /path_to_your/.htpasswd new_user

The -c will create the file .htpasswd for the first time.

After you do this, it will ask you for a password for that user. Then, that user and that password can be used to access the area.

Every Dir and File under that Dir will be password protected by this list (but can be overridden by other .htaccess files in other dirs).

Hope this info helps :)
 
Incidentally, htpasswd may not be pathed correctly so you may have to use its full path. To find that info out, do:

which htpasswd

A lot of hosts (especially paid hosts) nowadays have automated systems that will do this for you. I think there also some CGI scripts that do it for you.

Since PHP is usually not installed in CGI mode, and hence you cant run it command line, you prob wont find any PHP code...although someone may have written an interesting hack :)

Anyway, good luck :)
 
Back
Top