Sniptools » Tutorials

Windows, Apache and .htaccess authentication

May 26, 2003 Views (119,099) /  Comments (132) /  Trackback (1) / Digg/Share


Enabling password authentication on Windows using Apache (and here’s a link if you wish to RTFM) given the knowledge that you are busy folks so these are merely quick instructions to get it working on Windows.

Some things to know beforehand:

  1. Path to your Apache server (e.g., c:\apache)
  2. Path to your CONF folder (e.g., c:\apache\conf)
  3. Path to your DOCROOT folder (e.g., c:\apache\htdocs)
  4. Path to the folder you wish to password-protect. In my example, lets take a folder called “secure”, so the path to this would be “c:\apache\htdocs\secure”. (It could be ABOVE the htdocs folder as well, FYI).

Ok, let the show begin:

  1. Open up your httpd.conf. (On my machine this is at “c:\apache\conf\httpd.conf”).
  2. Look for the word called “AccessFileName”. I believe there should be a line like this:

    AccessFileName .htaccess
    

  3. If you use Windows 2000 or above, then move on to step 4 (because you can create files like “.htaccess” on your system which do not have anything before the dot in the filename. If not, then change this line to the following:

    AccessFileName ht.acl .htaccess
    


  4. Then, we need to add the directory to the configuration. Instead of rattling on about how to do it, here is a screenshot:


    This is what the HTTPD.CONF should look like.

    Please note that “/apache” in the directory path means that it starts from the root drive on my machine (“c:”). Adjust accordingly.


  5. Our httpd.conf is done. Now we need to create the password file. Open up a DOS prompt and go to the apache’s BIN directory. In my case, it is “c:\apache\bin”. Anyway, again, I think a screenshot is more helpful.


    Instructions for creating the password file




  6. Now, we need to create the HTACCESS file itself. As per point 3 above, either create a “.htaccess” or a “ht.acl”, whichever suits you fine. I will keep my example to “ht.acl” because this works on ALL windows systems if they use Apache 1.12…or above. Here is what this looks like.





    c:\apache\htdocs\secure\ht.acl
    



  7. Save the above file into your SECURE folder because it represents only that folder context.



READY TO ROLL! (I restarted my Apache, just in case). Here is what happens when I try to access my folder from the browser:

(366 Words | )

 
Possibly Related
Other stuff that may be of interest  
Comments
What readers have asked/said/added.

^1 mark said on May 31, 2003 11:07 AM:

how to enable url rewriting in windows? thank you so much for this tutorial but htaccess on windows is not very useful to me unless i can also use is to mirror my rewriting on my production server which uses freebsd. thanks for any ideas.

^2 Shashank said on June 6, 2003 12:17 PM:

Mark, did you enable your rewrite module in your httpd.conf? Uncomment this line if it exists:

LoadModule rewrite_module modules/mod_rewrite.so

Or just write it if it doesn’t already exist. That’s it.

^3 Xcape said on August 10, 2003 10:58 AM:

you need to put ” ” around the path to the password file, section 2.2.2.6

^4 Shashank said on August 11, 2003 11:43 PM:

Thanks Xcape. It works in the above example as there are no spaces in the path, but yes, if we had paths like this:

c:\program files\apache group….

..then quotes are useful! Thanks for the tip.

^5 John said on September 4, 2003 4:40 AM:

“If you use Windows 2000 or above, then move on to step 4 (because you can create files like “.htaccess” on your system which do not have anything before the dot in the filename.”


You sure? I can’t create a file named .htaccess in WIN2K

^6 riad said on September 11, 2003 5:56 AM:

hi,
the tutorial is very nice, but there is something i did not understand !! as soon as i made the htaccess procedure , my apche server become very HEAVY !! is that normal ??
thanks for answering

^7 Nickolas said on September 22, 2003 3:42 AM:

John> Windows 2000 (I’m using Advanced Server on my server) will not allow the creation of .htaccess files in the explorer, but if you save a notepad fiel as .htaccess, and rememeber to set the file type as “All types”, it’ll save the .htaccess file all well and good. And then copying and pasting the file works, as well as editing it’s content.

^8 Stuart said on September 30, 2003 6:43 PM:

First a very good tutorial, the best I have found on this subject.

A few comments. when creating a new file on windows XP (right click,new/text_file then rename to ‘.htaccess’) I get a system error ‘You must type a filename’. Then when I rename it to ht.acl my system thinks the file is a ‘AutoCorrect List File’ which might or might not cause problems!! I renamed it to ‘ht.ac’ Smilie
Then I added c: to the change in httpd.conf file as I assume this may be needed.??

I restarted apache and tested my newly secured folder…. I got the user/pass prompt Smilie but my username and password failed Sad :( - I have recreated my password file several times to check the spelling etc but the this has not helped Sad :(

If anyone has any suggestions please email me, or post here.

thanks

^9 Shanx said on September 30, 2003 9:05 PM:

Hi Stuart,

Thanks for the kind words. You’re lucky you’re on Win XP because I bet it works.

(1) For creating .htaccess, don’t create it inside Explorer. Open Notepad, type something and SAVE AS “.htaccess” and choose the file type as “ALL FILES”. Works without a croak.

(2) For Apache and your password file in general, I would delete everything and start afresh instead or renaming files etc. Just follow the instructions here from step 1. I created a new test secure folder and it works immediately. FYI, I tested this on my Win XP box which has Apache2 running. (Could test it for you on Win2K and Win98 as well).

Hope this helps! -Shanx

^10 Stuart said on October 1, 2003 5:39 AM:

Thanks Shanx,

I started again (removed the previous files etc) and it worked Smilie

Thanks agian,
Stuart

^11 Mike said on October 28, 2003 2:33 PM:

I’m using winXP with apache server I followed all the directions above but when I send my browser to the specific file, it says forbidden you don’t have access to /secure/ on this server. If I put a link from another page to it, it goes straight in without the asking about password or username, any ideas.

Thank you

^12 Shanx said on October 28, 2003 2:54 PM:

You must have some other settings in your HTACCESS that may be conflicting with these security settings. Can you perhaps share your HTACCESS file? You can email me personally if you prefer.

^13 topquark said on October 31, 2003 6:51 AM:

So has anyone been able to use windows authentication with Apache 1.3.x?

^14 Alok said on October 31, 2003 10:41 AM:

Yes, I have. Are you having problems with it?

^15 Will said on November 1, 2003 12:32 AM:

If you cant create a .htacess file in windows you can use dos.

1) Create a simple htaacess file in notepad just save it as “htacess” no “.”
2) Run -> Cmd
3) No we are in dos/command promptyness
Here
ren htaccess .htaccess

^16 immy said on November 9, 2003 4:21 AM:

Hi guys,

I’m running xp with apache version 2.0.47. I have created the .htaccess file and left the these lines in in my conf file



Order allow,deny
Deny from all


When i try to access the secure directory it lest me in with out any prompt for a password plus i dont see the .htaccess file listed when i get in through browser

can anyone advise me what i should do to get it to work

cheers

^17 Chris Traverse said on November 13, 2003 8:24 PM:

i followed the instructions to the letter (im running apache/1.3.29 on windows 2000). The first time i did it i just got an internal server error message. So i tried again and this time it justlets me access the files, no question of putting a password or username in.. Anyone else had these problems ?

^18 PatrikRoy said on November 16, 2003 1:02 AM:

Thanks for all, I tested it with Apache 2 on Windows 2000.
Works fine Smilie

^19 Shanx said on November 16, 2003 2:46 AM:

Chris Traverse, you need to tweak your HTACCESS file, most likely. If you still haven’t got it working, please write to me personally with a sample of your HTACCESS file attached. HTH, Shanx

^20 foxer said on December 20, 2003 12:17 AM:

This didn’t work just like this, i had to put:


AllowOverride All
Options None
Order deny,allow

instead just “/apache/htdocs/secure”

running apache 1.3.27

^21 jc said on December 29, 2003 12:27 PM:

Excellent tutorial

^22 John p. said on January 6, 2004 6:32 PM:

Wonderful tutorial.

I have noticed many tutorials out there giving code and so forth, but none mentioned directives.

So, am I to understand that [nc] or [r,l] is a directive?
If so, is there a specific .htaccess manual for this?

^23 H Rage said on January 9, 2004 7:04 PM:

When creating a .access file on windows systems:

Type one in notepad
Save As

“.htaccess”

It is important to remember the quotes; they’re the things preventing the .txt extension and the filename alert when you only use an extension.

^24 Nick said on January 11, 2004 9:44 AM:

Hi,

I am running windows 2003 and apache 2. I followed your instructions, but if i go to secured area it doesn’t ask me for login (#7)

here is my config please help as I need to bring my site live ASAP. thanks

Shashank’s Edit:
Your .htaccess file is here, due to the length

^25 ingenious said on March 3, 2004 9:19 AM:

Thank you- works like a charm with my apache 2 server

^26 Shashank said on March 11, 2004 11:31 PM:

Nick, Thanks for the htaccess file, but it was huge and made this page overflowing so I have moved it into a separate file on this server. As for the problem, where is your “Directory” directive? Pls read the instructions and follow them to the letter. Once it works, as in the example on this page, then try for your own paths etc.

^27 popeye said on March 13, 2004 8:32 AM:

hi all.

nice tutorial.

I was wondering. Is it possible if you already set up a protected folder to add users via a sort of webbased script.,so dont have to physicly be at the server, but can remotely add an user account

thnx

^28 Shashank said on March 13, 2004 10:29 AM:

Hi popeye, you can swing by this cool tool: http://www.awtrey.com/support/scripts/htpass.php ..this is CGI, but you can get an idea and implement this in whatever language you wish..HTH, Shanx

^29 Tony said on March 23, 2004 6:26 PM:

I tried in W2k, thx it works but I can find a log off feature - I can access the “secure” directory again even I closed the IE after accessing it!

Any suggestion on making a log off session?

^30 PyroLuna said on April 1, 2004 10:02 PM:

I got another trick to make windows accept filename .htacces
I have acces to a webdirectory and when I rename my file overthere, it’s no problem, so then I copy it back to my local protected directory et voila, it works! Smilie

^31 T_R_J said on April 8, 2004 8:31 AM:

Just wanted to thank you for having the answer I needed. Keep up the great work.

^32 jdang said on April 14, 2004 4:31 AM:

this is a nice tutorial but im having problems. i want to protect a director called “S04” in a directory called “jdang” in my htdocs. my apache is located in “c:\Program Files\Apache Group\Apache2”, so here is the relevant part of my httpd.conf file:

AccessFileName .htaccess

AllowOverride All
Options None
Order deny,allow


here is my .htaccess file (and yes, i properly named it as a .htacess in windows XP)

AuthUserFile “/Program Files/Apache Group/Apache2/passwd/passwords.txt”
AuthName “S04”
AuthType Basic


require valid-user


My password file is located in “C:\Program Files\Apache Group\Apache2\passwd\passwords.txt”

When i test it, i go to “http://xxx.xxx.xxx.xxx/jdang” I don’t see my folder “S04”. So, I manuall type in “http://xxx.xxx.xxx.xxx/jdang/S04” and it asks me for my username and password, and it accepts the username and password, but it comes up with this error:

Forbidden

You don’t have permission to access /jdang/S04/ on this server.

I know my username and password is correct because if i type in an incorrect combination it will just prompt me for my username and password again.

Sorry for the really long post, but could anyone help me?

^33 gateway said on May 12, 2004 6:40 AM:

Thanx very much for this tutorial!
I search around day and no one could help me!
Now it works….
Thanx

^34 Brandon said on May 27, 2004 1:52 PM:

I’m having problems wiht this tutorial. Everytime I keep trying to access my folder that I set for authentication, it gives me a forbbend message. Here is my .htaccess file:

AuthUserFile “C:/Program Files/Apache Group/Apache/bin/passwd.txt”
AuthName “This is my secret area”
AuthType Basic


require user beetle

Can some one help. Thank you.

^35 esophal said on June 1, 2004 7:28 AM:

When I upload .htaccess or ht.acc to any directory on my server, my entire website got effected.

eg. when I create directory called secure, even my main / request for login.

Please help…

^36 Shashank said on June 1, 2004 9:30 AM:

Hi guys,

The instructions in the tutorial above work for any Apache installation on any version of Windows.

If you are having problems even after making SURE that you have followed the instructions above, then the only other possibility is that you have something in your htaccess file that conflicts with the new instructions.

In this case, the only way out is for you to send me (privately) your .htaccess file and let me look at it for possible anomalies.

Thanks,
Shashank

^37 cap'n said on June 3, 2004 1:33 PM:

I’m using Apache 2.0.49 on Win2k
I’m using a .php script over Apache and set the
$z_apache_auth = true; # Append Apache user:password to playlist urls.
This is working fine for winamp… but my linux friends with xmms aren’t getting in..

dealt with this scenario?

^38 Olmen said on June 10, 2004 2:37 AM:

Why doesn’t the secure folder list in the root folder of the server.

E.g. the folder /secure does not show up at all, you have to type in the address manually…

^39 Shanx said on June 11, 2004 11:09 PM:

Hi Olmen, I am not sure I understand the question. What is your path structure?

^40 Jesse said on June 19, 2004 7:43 AM:

I don’t know what the problem is….I followed your instructions exactly, but when i go to the directory that is supposed to be protected, I keep getting:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@123456.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


————————————————————————————————————————

Apache/2.0.49 (Win32) Server at 12345.afraid.org Port 80

my docroot is C:\webroot, Apache is under C:\web servers\apache2. If there’s anything else I should be doing, please tell me. Thanks in advance!

^41 Punk said on June 20, 2004 2:24 PM:

Jesse-
If a path in the .htaccess file has spaces in it, you must enclose it (the path) in quotes.

8^)

^42 kaushik said on June 24, 2004 6:11 PM:

hi

the tut is really nice

my phpmyadmin path is c:/phpdev3/www/html/phpMyAdmin

my docroot folder is c:/phpdev3/www/html

my apache BIN folder path is c:/phpdev3/apache/bin

I want to prevent acceess to the phpMyAdmin folder so i created a passwd.txt file as required in BIN folder of Apache….

I added the necesary comments to the httpd.conf file in the CONF directory of Apache…..

& i created a .htaccess file in the phpMyAdmin folder with the necessary contents……

but when I try to access phpMyadmin folder, it tells me the following message

Forbidden
You don’t have permission to access /phpmyadmin/ on this server.
————————————————————————————————————————
Apache/1.3.19 Server at ballast Port 80

it does NOT ask me for the username & the paassword

^43 Shashank said on June 28, 2004 9:35 AM:

Kaushik,

Can you share the section of your httpd.conf? I believe your path there may be wrong, or it may be conflicting with another directive in your file.

Shanx

^44 evil said on July 3, 2004 2:02 AM:

ok ive got it to ask me for a user and pass hurrah Smilie

but i then get the message Forbidden
You don’t have permission to access /secure/ on this server.

what have i missed ?

tia.

^45 revertzero said on July 8, 2004 7:43 PM:

This is a great tutorial, definitely the best I’ve seeen on the subject.

Similarly to others I think I’ve got a conflicting directive as once I am presented with the pop up box and I correctly enter my login details I get the following message:
“Forbidden
You don’t have permission to access /si/ on this server.
————————————————————————————————————————

Apache/1.3.27 Server at localhost Port 80”

My Apache access log states
“127.0.0.1 - irfan [08/Jul/2004:12:20:20 +0200] “GET /si/ HTTP/1.0” 403 304”

My Apache error log states
“[Thu Jul 08 12:20:20 2004] [error] [client 127.0.0.1] Directory index forbidden by rule: d:/home/www/si/”

My ht:acl file reads:

“AuthUserFile “c:/Program Files/EasyPHP1-7/apache/bin/passwd.txt”
AuthName “Documentation Area”
AuthType Basic


require valid-user

Is this in contrast with my httpd.conf file directives ?


DocumentRoot “D:/home/www”


Options FollowSymLinks Indexes
AllowOverride All

Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all


AllowOverride All
Options None
Order deny,allow

Thanks for pointing me in the right direction

^46 revertzero said on July 8, 2004 8:13 PM:

PROBELM SOLVED :P

(IfModule mod_dir.c)
DirectoryIndex index.html index.htm index.shtml index.php
(/IfModule)

my index file had a .htm extension and .htm wasn’t listed in the above.

sorry for all the messages but at least you can now say that this tutorial is so great it even works on NT ;)

thanks!

^47 dstack said on July 13, 2004 10:40 PM:

Great tutorial! This helped me out of a jam this morning. Nice work…

^48 Chris said on September 8, 2004 3:56 AM:

Heres somthing a bit difficult… i followed your tutorial like so and when i got to access the protected directory i get a 500 Internal Server Error… here are the specs.

Operating System: Windows XP Pro SP2
Apache Server Version: 2.0.50

httpd.conf file:
http://www.itxserv.com/myhttpdconfigfile.txt

ht.alc file:
http://www.itxserv.com/secure/ht.alc.txt

Any suggestions would help….

^49 Chris said on September 8, 2004 3:58 AM:
^50 Chris said on September 8, 2004 11:21 PM:

nevermind.. i fixed it lol… Excellent tutorial btw..

^51 Matt said on September 9, 2004 3:38 AM:

This guide is the by far the best I have encountered. I have no prior Apache experience and this saved me big time.

Thanks!

^52 elwyn said on September 13, 2004 1:16 PM:

This tutorial is good. But i have one question here.
If my Apache is different in a different server with my web applications. How do i set the path for the in httpd.conf

AllowOverride All
…………….
…………….

Can anyone please help?
Thank you.

^53 Shumam said on September 14, 2004 2:37 AM:

#
# Based upon the NCSA server configuration files originally by Rob McCool.

[trimmed due to size]

^54 Shumam said on September 14, 2004 2:38 AM:

above is my httpd.conf……I’m using winXP with apache server I followed all the directions above but when I send my browser to the specific file, it says forbidden you don’t have access to /secure/ on this server. If I put a link from another page to it, it goes straight in without the asking about password or username, any ideas.

^55 jkue said on September 14, 2004 3:20 PM:

Shanx,
have you thought about a forum? it is hard reading such long posts (nothing against the persons), for me anyway.

Please, post ONLY the relevant points in your solutions guys and gals. This makes it easy to evaluate, the usefulness and accuracy, and also makes easy reading.

^56 Shumam said on September 15, 2004 5:53 AM:

I am really sorry for any disruption. If admin wants to take it off, no problem. But if any body knows the problem please do let me know. thanks

^57 jkue said on September 15, 2004 3:42 PM:

Your problem Shumam lies here (look at the arrows —>). You have given rights, but in the alias taken it away also. This should be corrected, either None or All.
——— SNIP ———
DocumentRoot “/web tools/machine_reporter/”
AccessFileName ht.acl .htaccess

AllowOverride All —> Allow All
Options None
Order deny,allow


Alias /machine_reporter/ “C:/web tools/machine_reporter/”

Options MultiViews
AllowOverride None —> Allow None for the same folder.
————- SNIP —————

tips:
- Check your Error_Log file in “c:/web tools/logs”. The answer is always in there.
- try not to use spaces in the names of folders (“web tools” should be “web_tools”), this is better.

reply:
Notice I did not correct it for you? I wanted you to get use to searching and correcting errors(I presume you are a Admin). Trust me, this is the best way, and incase it doesnot work, you have a start where and how to look.

I did not mean it like it sounded above, I apologise.

^58 jkue said on September 15, 2004 4:02 PM:

Shumam forget the crap from above(if that’s not working)the error Forbidden is because you do not have an index.html, index.php etc. file in the secure folder. People, do y’all remember this setting in your htconf file? -Indexes

This means noone is allowed to browse the folder when there is no index file. So, create an index file in the secure folder, tada!!.

^59 Shomam said on September 17, 2004 2:54 AM:

That works! thanks

^60 Lars E said on September 24, 2004 10:36 PM:

Thanks for providing this great tutorial. Its so much easier following examples than just reading about features without seeing them applied in a context! Good on you mate;)

^61 Dave said on October 6, 2004 3:46 AM:

I am not prompted for any file names can you look at this and see what I did wrong. thanks

DocumentRoot “D:/Program Files/Apache Group/Apache2/htdocs”

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all

UserDir “My Documents/My Website”


AllowOverride ALL
Options None
Order deny,allow


AllowOverride ALL
Options None
Order deny,allow

DirectoryIndex index.html index.html.var
AccessFileName .htaccess


Order allow,deny
Deny from all

TypesConfig conf/mime.types
DefaultType text/plain

MIMEMagicFile conf/magic

^62 Shanx said on October 21, 2004 8:46 AM:

Dave,

Which folder do you wish to secure? I’ll assume it is the “admin_phone” folder.

1. Make sure your “AccessFileName” command is ABOVE any of the DIRECTORY directives.

2. Make sure the .htaccess file is in the “admin_phone” folder.

Actually, before you try an admin_phone folder, can you try the example mentioned above, as-is, including the folder names etc?

^63 Sean said on October 31, 2004 12:37 AM:

This tute was just what I needed, had spent nearly 1 week trying to make .htaccess run locally like it does on my server, no joy atall ti’l I used this method of creating the password file, also using the .htacl extension if the appache httpd file helped I think, muchos thankos for this. regards.

Sean

^64 Riya said on November 6, 2004 6:32 AM:

Thanks for providing this great tutorial.

Thanks,

^65 Brian said on November 17, 2004 2:31 AM:

Finally made it work - but the process was complicated by the existance of “Virtual Hosts” on my server. And that part is not covered here.

In another set of instructions (somewhere), I remember vaguely, that entries are to be made into that virtual hosts section, if that’s where the portion of the server and host to be secured is located. Nothing worked (no username/password challenge) until I added lines to the main Httpd.conf section just under “AccessFileName .htaccess” line up there.

Anyway, I got quite confused over all this and would appreciate some specific instructions when “Virtual Hosts” is involved.

Thanks,

Brian

^66 Pierre said on November 23, 2004 2:37 AM:

Great tutorial, but i can’t get it to work properly, have tried several things with various results, right now it doesn’t ask for a password.

Could anyone please help me?

^67 Paul S said on December 9, 2004 1:20 AM:

jkue nailed it….I had the same access problem (forbidden) until I added the index file to the directory that was protected. Otherwise the tutorial is excellent.

^68 James said on January 2, 2005 11:25 PM:

I found the apache manual to be sufficent for instructions on .htaccess and what to do, even for the beginner like me

^69 Takrim said on January 4, 2005 9:34 PM:

Hi,
This tutorial is really wonderful.I have gone through the steps and implemented the steps as stated by you. but i do not get any pop-up window asking for username and pswd.
I am using Win2k with apache server.

^70 TeDaDeS said on January 14, 2005 7:05 PM:

If anyone thinks its insecure to send your unencrypted password over, and over again to the website use these settings:

———————-
.htaccess
———————-
AuthType Digest
AuthDigestFile /u/soft/www/secure/.htpasswd
authname “Secured Login”
———————-

This setting will enctrypted your password (MD5) before sending it to the website. Mind this: the data send/received are not encrypted!

What is the use of this:
When you receive a 401 error, you a promt to login. When you do, your browser will remind your password so the next page will not promt you again. But your browser will log you in automatically.
You don’t mind, but your password will be send over-over and over again unencrypted over the internet.
A simple network sniffer could receive your internet traffic and retreive your password.
This setting will make that a bit harder to do.

Mind this: Older browsers might not support this feature (IE 4.0&lower).

^71 Lebanese_007 said on January 16, 2005 9:19 AM:

TeDaDeS, where do you put this code?
AuthType Digest
AuthDigestFile /u/soft/www/secure/.htpasswd
authname “Secured Login”

i tried putting it in ht.acl and when i tried to access the site, the broswer gave me an error saying that “The server encountered an internal error or misconfiguration and was unable to complete your request.”

any help please

^72 LcF said on January 26, 2005 12:54 PM:

Does the paths work on long file name?

^73 ixiel said on February 2, 2005 6:54 PM:

superb tutorial!

to those who had problem please try this tutorial as it is first.

u will much understand the flow and easier when you want to try your own setting.

one more thing to remember, try change to this setting in the IE > Tools > Internet Option > Temporary Internet Files > Choose every visit to the page.

I managed to setup my own htaccess. It works fine if i restart apache(after make adjustment to httpd file) & reload IE but fail when i click GO button. So the workaround to this problem is as above. (“Choose every visit to the page”).

Good luck!

Thanx for this wonderful tutorial! Bravo!

^74 Chimo said on February 13, 2005 12:19 PM:

I haven’t see anything about the fact apache usually forbid all user to access .ht files. If you decide to use anything else than .htaccess like :

AccessFileName foo.txt

You should change this in httpd.conf :

Order allow,deny
Deny from all
Satisfy All


According to this it also mean that you can place your password.txt in the same folder than .htaccess and rename it to .htpasswd or .htanything_you_want. Nobody will be able to get it.

In the case of foo.txt I guess the following should work:

Order allow,deny
Deny from all
Satisfy All

password file can be something like foo.txtpasswd

^75 etegration said on February 18, 2005 1:16 AM:

My error log shows

“[Sat Feb 19 00:13:00 2005] [alert] [client 218.212.23.129] C:/Program Files/Apache Group/Apache2/htdocs/phpmyadmin/.htaccess: AuthUserFile takes 1-2 arguments, text file containing user IDs and passwords”

the passwd.txt is in C:/Program Files/Apache Group/Apache2/bin/ already but it seems it’s returning an error saying it’s not. Why?

I’m trying to protect C:/Program Files/Apache Group/Apache2/htdocs/phpmyadmin/

^76 Paul D Wilson said on March 1, 2005 2:52 PM:

hey this might be stupid but I dont know the answer, and you guys seem to know a lot about it. Everything i have is working fine, the tutorial for everything worked great. but i dont know what it should look like in my passwd.txt file. I know the username and pass goes in there, but ive tried to put

username cat
password dog

and nothing works. plus im sure its not encrypted, should I worry about that and if so ,what should I do about it?

pauly

^77 Paul D Wilson said on March 1, 2005 3:07 PM:

Ok, I just posted something, but I did the whole cmd prompt thing to encrypt the password in the passwd file and it worked, perfectly! but It wont let me in when I put in the info!

pauly

^78 Megan said on March 8, 2005 6:18 PM:

I have managed to set up htaccess on an externally hosted website but am having trouble setting it up on the local machine. I think my problem is with the directory setting in .htaccess.

The directory to be protected is:
C:\www\private
The password file is called passwds and is in the directory passwords, i.e.:
C:\www\private\passwords\passwds

My apache server is under:
C:\Program Files\PHP Home Edition 2\Apache2

Do I put in my AuthUserFile: “/private/passwords/passwds” (minus the “”),or;
“localhost/private/passwords/passwds”, or;
“C:/www/private/passwords/passwds”, or some other possibility that hasn’t occurred to me yet?

I have set the httpd.conf file to “AllowOverride All” for the directory C:/www, so the prompt box for login now shows up, but I suspect that it cannot find the passwds file which is why I cannot log in.

Any advice would be appreciated.

regards
Megan :o)

^79 prod-is.com said on March 18, 2005 5:35 AM:

Great, Works just fine ! thanks for all .

^80 Shashank said on March 29, 2005 9:29 PM:

Megan, and others, please make sure that you’re using the path to Apache as demonstrated in this tutorial. I know Apache installs into “c:\Program Files” which is the Windows default, but Program Filles has a space between the two words, which is a cause of headache in most occasions. If it’s not too much of a bother, reinstall your Apache to c:\apache or something. And retry JUST AS SHOWN in the tutorial on this page. Let me know if problems still persist.

^81 Igor said on April 18, 2005 10:36 PM:

Resime:
XP, Apache 1.3
1)
Create passwords file:
C:\oracle\splet\Apache\Apache\bin>htpasswd passwd.txt marko
Automatically using MD5 format on Windows.
New password: *****
Re-type new password: *****
Adding password for user marko

… and so on, for adding new users… (without -c) Password for my marko is: marko

2)Under htdocs create directory: safe_dir

Open Notepad, write:
AuthUserFile c:/oracle/splet/apache/apache/bin/passwd.txt
AuthType Basic
AuthName “Safe dir 1”
Require user marko metka

Save as ht.acl into the safe_dir

3)
Open httpd.conf and find and change:

# This controls which options the .htaccess files in directories can
# override. Can also be “All”, or any combination of “Options”, “FileInfo”,
# “AuthConfig”, and “Limit”
#
##AllowOverride None —comment it out
AllowOverride All

4)
Create test.htm and save it in safe_dir

5)
Run Appache, test access to the test.htm


Why original manual above did’t work on my PC:
I create ht.acl instead of .htaccess
I create passwd.txt instead of passwords

regards
Igor

^82 Tom said on May 8, 2005 2:18 AM:

Hi there,

I’ve been trying to protect access to a folder following the steps explained in the tutorial, but the problem now is that I can still access the folder using my explorer. There’s no box asking me for y username and passwd…

I did the following:
- In my http.conf file, I added the following:

AccessFileName .htaccess

AllowOverride All
Options None
Order deny,allow

I created the passwd.txt file in the folder
D:\Program Files\Apache Group\Apache2\bin

After that I created the .htaccess file containing the following info:

AuthUserFile “d:/Program Files/Apache Group/Apache2/bin/passwd.txt”
AuthName “This is my secret area”
AuthType Basic

require valid-user

I saved this file in the following folder:

d:/Program Files/Apache Group/Apache2/htdocs/secure

After that I stopped Apache and started it again.
I opened my browser, typed in ‘localhost/secure’.
The content in this folder was displayed.

How can I solve this problem?

Thanks,
Tom

^83 AlexCoates said on May 26, 2005 5:39 AM:

Hello,
I set up authentication on my site using your tutorial and I thank you very much. however I have a question. I set up authentication on my machine running Apache 1.3.33 and it works perfectly. I tried to set it up on my friends machine running Apache 1.3.27 and it only partially works. I copied all the settings from my machine to his and set up the aliases. When you try to go directly to the restricted file ‘modify.pl’, you are asked for a username and password. However if you click on a link from the current page to ‘modify.pl. you are not prompted for a username and pass. Does anyone have an idea? Is this a bug with that version of apache and url re-directing? Any help would be nice…here is my config set up:

httpd.conf:

AccessFileName ht.acl

ScriptAlias /cgi/ “C:/computers/cgi/”


AllowOverride All
Options ExecCGI
Order deny,allow
Allow from all

ht.acl file:
AuthUserFile C:/computers/passwd.txt
AuthName “Enter user name to Edit”
Authtype Basic


require valid-user

and my password file is located C:/computers/passwd.txt

This works fine if i go directly to the page or if i go using a link on my Installation, but it doesn’t ask for authentication on my friends when re-directed from another page. Anyone have an idea?
Thanks Alot and great tutorial,
Alex

^84 Sam said on May 27, 2005 6:07 AM:

Hey, I have followed this great tutorial but I was unsuccessful. I get to the password prompt, but I can’t get past that. I have an index.html as well.

^85 joey said on May 30, 2005 2:34 PM:

can you do any formatting of that password popup window? change the font? multiple lines? images?

^86 Shashank said on May 31, 2005 11:12 AM:

Hi Joey,

The window will most likely appear differently on different browsers and different OSes.

Although you can change the message that a user sees by inserting a newline character (“\n”) in your AuthName text. This should allow multiple lines.

A customized login that coincides with the rest of your site is neat from a design point of view, I guess, but do you really want to spend that much time on a login screen that a user spends no more than a second on? Especially with all modern browsers supporting “Remember password” functionality.

FWIW, you can customize the error message that appears if the user cancels the login by customizing Apache’s Authorization Required (401) page.

Shashank

^87 Sameer Pal Singh said on June 12, 2005 2:24 PM:

Dear Sir,

I was stuck in my office for this reason, i was not able to do make password protected directory on client’s site. i got this page from google and i tried, hoooray it is fantastic i done it. thank you for CEO, developers…of this site. and i m very glad to see the Indian name below this page Mr. Shashank Tripathi as as Indian. Thanks a lot to everybody there.

Thanks & Rgds,
Sameer Pal Singh
sameerpalsingh@rediffmail.com

^88 Liz said on July 21, 2005 12:06 AM:

I must agree this is an awesome post and was very helpful. I followed the steps although once everything was complete and I went to see if it would asking me for username and password it didn’t. Im not sure what’s exactly wrong. Im running windows 2000 and apache 2.0.53 If someone might be able to point out what’s wrong that would be great.

^89 Shashank said on July 21, 2005 12:54 AM:

Liz, others for whom the tutorial doesn’t work. Please make sure you have the paths in your files properly specified and put inside double quotes if you have spaces in your folder names.

For instance, on my Apache2, my .htaccess file looks like this:

—————
AuthUserFile “d:\Program Files\Apache\Apache\bin\passwd.txt”
AuthName “Secret area”
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
—————

And my httpd.conf entry looks like this:

—————
<Directory “d:/program files/apache group/apache2/htdocs/sniptools/secure”>
AllowOverride All
Options None
Order deny,allow
</Directory>
—————

^90 Radicator said on July 29, 2005 3:28 AM:

Excellent tutorial. I followed your instructions and it worked first time perfectly on my WinXP machine.

I’d been searching for a good explanation of how to do this for some time and this one actually did the trick.

Thank you!

^91 Tormu said on August 9, 2005 11:39 PM:

Thanks, this one really helped, I did know how to protect the directory in other webspaces, but this one showed me what to do with the apache conf on my own web server Smilie

^92 Rattlehead.ie said on September 6, 2005 1:10 AM:

Dude thanks very much for this very imformative + view of the created .acl files is a great advantage. Just out of interest how secure is using this method?

^93 Chris said on September 23, 2005 3:53 AM:

Great writeup! However, I noticed with Apache2, Apache uses the “httpd.default” .conf file instead of the httpd one. I don’t know if this is just me, but just thought I’d share, because I was having fits getting it to work until I realized this.

^94 twig said on October 28, 2005 10:12 AM:

thanks for that very detailed tutorial!
got my server protected very quickly!

^95 Mark said on November 1, 2005 8:53 AM:

Cheers for the easy-to-follow instructions.

I have managed to get the thing working, but I have to enter the username/password twice, in identical login windows, before Apache will let me in. Not a serious problem but a minor irritation that I would like to deal with if anyone can help.

^96 WDR said on November 15, 2005 10:55 PM:

I have do like your instruction with Apache 2.0.55 but can not ! when I log in to http://localhost everything as normally without password protecd ! Could you please help me !

Thanks.

^97 Ray said on December 3, 2005 5:50 PM:

Having some trouble.
running Win xp pro service pack 1

.htaccess file looks like this

AuthUserFile C:/Apache Group/Apache2/bin/.htpasswd
AuthName “Members Area”
AuthType Basic


required Valid-user

config file looks like this

AccessFileName .htaccess


AllowOverRide All
Options None
Order deny,allow

When I try to test it , it gives me a 500 internal error

Can anybody help

Email: ghost1@nctv.com
subject .htaccess

thanks in advance

^98 miro said on December 18, 2005 5:56 AM:

In the .htacces file I have:

AuthUserFile D:\streznik\www\reiki.htpasswd
AuthName “Members”
AuthType Basic


require valid-user


and in the .htpasswd I have:

admin:$apr1$Qh/…..$zBrg27pYbkwKIWypvMQQ6.

Created by command prompt :
htpasswd -c -b .htpasswd admin test

it gives me 500 internal error with the comment in the error log:

d:/streznik/www/reiki/.htpasswd: Invalid command ‘admin:$apr1$Qh/…..$zBrg27pYbkwKIWypvMQQ6.’, perhaps mis-spelled or defined by a module not included in the server configuration

Directorz settings:

DocumentRoot “D:\streznik\www\reiki”
ServerName reiki.petyasfreeworld.com

# Other directives here

AllowOverride AuthConfig
Options None
Order deny,allow


I also tried with AllowOverride All, but nothing changed.

I have Apache 1.3 on Windows 2000. It’s pretty rare configuration and I’m not sure that .ht files works there. Can you help me? I would like to stay on this configuration, because I’m not familiar with *nix systems.

Please help.

^99 Dave said on December 30, 2005 4:13 AM:

I’ve have many of the same “Forbidden” errors you have all had. Finally figured it out. I assume most of you are viewing Directory Indexes…

So

You need to have the following instead:
AllowOverride All
Options Indexes None
Order deny,allow

Without “Indexes” you will lose access to the directory views once you login.

^100 Mangal said on January 24, 2006 9:10 PM:

Hi ,

I tried with the above tutorial . I found internal server error.When i checked my error log i found follwing statements:

/stage/app/reportsdata/.htaccess: Invalid command ‘AuthUserFile’, perhaps mis-spelled or defined by a module not included in the server configuration.

As i am sure AuthUserFile is not mis-spelled . The 2nd one tells about the required module. If anybody has any idea on this module please help me out.

^101 Shashank said on January 25, 2006 2:20 AM:

Mangal— in the modules section of your httpd.conf, is the following module enabled (does not have the hash sign at the beginning of the line) — mod_auth_db? Shashank

^102 Mangal said on January 25, 2006 2:43 PM:

Thanks Shashank.

Now i am getting the username and password pop up.When i am giving the username and password as i have created in the passwd.txt file, it failed.I tried all the steps once agin but the found no result.Can You suggest something.

^103 Shashank said on January 25, 2006 10:17 PM:

If the password isn’t working, your password file is either being saved in the wrong place, i.e., it is not consistent with the path in the ht.acl (under the section “AuthUserFile”), or you are entering the password incorrectly.

^104 VincentT said on January 28, 2006 2:28 AM:

Top tutorial! I have been trying to get this htaccess thing working for several weeks now, but nothing worked. The very first time I did things according to this tutorial it worked right on! Great!

Thanks!

^105 Mauricio García said on February 6, 2006 10:37 AM:

Thanks for all, this tutorial is very easy, and good, i am not use .htacces all configuration in the config file httpd.conf

: = )

^106 Jérémie said on February 20, 2006 9:27 AM:

Thanks a lot for your succint and precise help.

^107 Lsa said on March 30, 2006 4:55 AM:

Hi Shashank,
I’ve got Apache 2/php5/mysql5 running on Windows 2003. I ‘m interested in creating websites for each of our staff members—say about 50 users. These websites will not be publicly available, they will mirror websites on our public website, and once the information has been approved the files will be transferred to their duplicate public sites by the administrator.

My question, is this htaccess authentication method the way to password protect these “not public” directories? I’ve got a basic understanding of namevirtualhosts but I’m very confused on how to set-up Apache for multiple users with different passwords. And if possible, I’d like it to be setup so that these folks can use their existing network passwords.

Any assistance or direction you can provide would be GREATLY appreciated, I’m googled out and I still don’t know what approach to take.
Lsa

^108 shajil said on April 28, 2006 7:02 PM:

I have followed the step which you have given i am getting the window asking for the username and password, i have given the username and password that i have created on passwd.txt also created ht.acl file inside the secure folder

My problem is login cardinels are not validating pls advise me for the same

^109 Petrucci said on May 27, 2006 11:49 AM:

Hi guys, i followed the tutorial, and i think im doing exactly as it says, but it doesnt work, the password box is not prompting.

here is my htaccess file

AuthUserFile “c:/apache2/bin/passwd.txt”
AuthName “lalalal”
AuthType Basic


requiere valid-user

^110 Yayan said on June 6, 2006 12:42 PM:

hii frend i have try it but when i restart the apache still zero ,no change i use windows 2000 profesional,
and this configuration
Apache(1.3.23),
MySQL(3.23.48)
PHP(4.1.1).
any body help me

^111 Marco said on June 7, 2006 7:38 PM:

Thank you for the quick-manual! Helped me get the .htaccess to work also in Windows! Tooks some loooooongs nights to tweak this out Smilie

One thing that was keeping me unsuccessfull was that I used those long filenames in the paths, e.g.

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

but after changing them all (including the path to the password file) to “DOS-Friendly” the system started to work without any problems - e.g.

C:/PROGRA~1/APACHE~1/Apache2.2/bin/.htpasswd

^112 Sander Thalen said on June 22, 2006 11:10 PM:

Just a thank you. It works as described for.

^113 Chris said on June 23, 2006 12:07 PM:

Thanks alot Marco

^114 Alexander de Boer said on June 26, 2006 11:19 PM:

Nice tutorial, but I have one problem. I configured my Apache and now all my sites get an 403 error and at no one a prompt to login.

^115 newjim said on June 29, 2006 3:37 AM:

I can get the Apache challenge box to come up, but it does not accept my password, but keeps popping up the challenge box.

This also occurs when I pop up the challenge box directly, that is, without having an .htaccess file:

The problem is that when I add the login and password, there is no $_SERVER[PHP_AUTH_USER] or $_SERVER[PHP_AUTH_PW]. I can confirm that by commenting out the lines above, inserting:

print_r($_SERVER);

and submitting the Apache challenge box. The display of print_r does not include variables for PHP_AUTH_USER or PHP_AUTH_PW.

I’m using Apache 2.0 and PHP 5.1.4

^116 newjim said on June 29, 2006 5:04 AM:

I answer my own question:

The box that I was working on had PHP installed as a CGI executable. When you load PHP as a module, as indicated in the tutorial, it works, even on Windows.

^117 relay_denied said on July 4, 2006 3:56 PM:

Thank you very much! This worked fine on my WinXP Home w/ Apache 2.2.2, PHP 5.1.4, i.e. 6, Firefox 1.5. all on my humble little notebook. I am amazed this thread is over 3 years old. Thanx for sticking with it and helping all of us either getting back on board or just breaking in!

^118 anand said on July 13, 2006 8:48 PM:

nice tutorial

but my username and password is not working. it just say ur not authorised.

^119 vita said on July 28, 2006 10:01 AM:

thank you man!!!! you really help me with this small tutorial.everything working great.

^120 thienhat said on August 3, 2006 1:51 AM:

i have problem with forbidden erros

and I check my logs error

here it is
[Wed Aug 02 11:36:47 2006] [error] [client 127.0.0.1] File does not exist: C:/Apache2/htdocs/favicon.ico, referer: http://localhost/

where do i get favicon.ico

please help

^121 Habib said on August 17, 2006 5:47 AM:

Hi,

Can somebody help me with my problem. I created one of those web sites that will ask you for your pass word on Windows. However, when I enter the password, it looks like that the pass word is not recognized. I am not sure what I am doing wrong.

Thanks for your help.

^122 Ricky said on October 21, 2006 9:21 PM:

Hi,

I keep getting an “Internal Server error” . Other pages on my webserver can be accessed but this error shows when i try to access the ‘secure’ folder.
My .htaccess file is exactly the same as in the steps above.

Any advice will be much appreciated.

Ricky.

^123 Dan W said on November 13, 2006 7:43 PM:

I followed the instructions to the letter and still get a “500 Internal Server Error” when I tried to access the “secure” folder. Error file shows the following line:

[alert] [client 192.XXX.XXX.X] C:/Program Files/XXXXXXXXXXX/ht.acl: AuthUserFile takes 1-2 arguments, text file containing user IDs and passwords

Running Apache 2.0.55 with PHP 4.4.3 installed on a Win2k Server box. The passwd.txt file in the /bin/ contains my chosen username and the encrypted password.

^124 phil said on November 21, 2006 4:49 AM:

Hello, I am trying to get password protection working on my apache windows 2000 system.
I have followed everything exactly as the tutorial and read many other web help pages, however I only get “403 forbidden you are not authorised to view this page” errors when I try to enter the password protected folder.

My config file is uploaded here: http://www.bphprint.co.nz/config.txt

My htaccess file is uploaded here:
http://www.bphprint.co.nz/htaccess.txt

Can someone please help me out. PLEASE SOMEONE help me. I have been trying for hours.

^125 Neo said on December 21, 2006 3:37 PM:

This tutorial is fabulous, It works for me. Thanks for all the great effort to depict things so nicely

^126 espido said on January 13, 2007 9:59 PM:

hi. i’m from lima peru. interesting the manual.

^127 TNT said on March 18, 2007 5:58 AM:

Hey! I’ve solved this problem!!! I just had to skip the step 4. Now everything works just perfect! Thanks for the tutorial!

^128 David said on March 27, 2007 9:32 AM:

Great tutorial, but couldn’t get it to work - kept denying my username/password … until I read down the comments and found Dave’s post some 15 months ago:


“I’ve have many of the same Forbidden errors you have all had. Finally figured it out. I assume most of you are viewing Directory Indexes.
So you need to have the following instead:
AllowOverride All
Options Indexes None
Order deny,allow
Without “Indexes” you will lose access to the directory views once you login.”


Yes, I was viewing directories and this fixed it for me. In the httdp.conf, “Options None” needs to be changed to “Options Indexes None”.

Thanks Dave for resolving this for me - and thanks to whoever is responsible for keeping this thread open for so long!

^129 joe said on April 27, 2007 2:39 PM:

ok i got the pass word working and all but i enterd it in wrong one time and now it wont let me enter it agin and it says forbeden every time i try to here is what the error log says hope u can help
[Fri Apr 27 00:22:58 2007] [error] [client 127.0.0.1] Directory index forbidden by Options directive: C:/Apache2.2/htdocs/pass/, referer: http://localhost/

p.s i know my english is bad

^130 donvoni said on May 1, 2007 4:49 AM:

Ive set up an Apache2 server on my WinXP home machine. its all goodie until i want to access my /secure folder. then i get a user/password request window. but it wont accept my user login. after 3 tries i get “Authorization Required” message. plz help. ive tried everything thats been said until this post =)

^131 Jesse said on May 7, 2007 8:16 PM:

For those who do NOT get a user/pass window:

Make sure that you set “AllowOverride” to “All” instead of “None” inside httpd.conf (not just in .htaccess). The “AllowOverride” setting might occur a couple of times, so make sure you set all that are needed. For example the “AllowOverride” settings in the directive


and

^132 Arial said on June 13, 2007 1:33 AM:

Nice guide. Took me a little while to figure out that this just doesn’t work with when trying to access index directory listing. You must point to a specific page or file or else you will get a restricted error.
Few have posted fixes for this with a simple change in the conf file, but for my need, just including an index.html file. That is all I wanted in the first place.

 

Post a comment
Please be decent while posting comments, don't make us delete them, thanks.




Will be spam-protected.

Remember?


Comment Preview

XX said on :

 

Trackbacks
Ping @ http://sniptools.com/ping/2003-05/2. Listed below are links to weblogs that reference this article.

Restrict Access Using Htaccess on Windows
Excerpt: I wrote a simple web application for stock management to be used inside the company(by only a staff). I got a request to implement password protection to the system. I do not want to modify database and modify the codes(and I am lazy :P ). So, the …
Weblog: LiewCF.com - Tech Gadget Blog
Tracked: February 1, 2005 1:24 AM

 

Referrals
*Some* places that viewers have come to this page from: