Windows, Apache and .htaccess authentication
It is quite simple to use .htaccess on Windows. Simple instructions with screenshots here.
//Windows下apache+.htaccess认证的设置,03年的文章有些老了。
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:
- Path to your Apache server (e.g., c:\apache)
- Path to your CONF folder (e.g., c:\apache\conf)
- Path to your DOCROOT folder (e.g., c:\apache\htdocs)
- 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).
下手之前,先要知道apache安装位置,apache配置文件的位置,网站目录位置和要保护的目录。
Ok, let the show begin:
- Open up your httpd.conf. (On my machine this is at
“c:\apache\conf\httpd.conf”). - Look for the word called “AccessFileName”. I believe there
should be a line like this:AccessFileName .htaccess
- 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
- Then, we need to add the directory to the configuration.
Instead of rattling on about how to do it, here is a
screenshot:alt="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. - 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.alt="Instructions for creating the password file" />
- 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
- 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:
what happens when I try to access my folder from the browser:
转载于:https://blog.51cto.com/netseagull/170374