I have a .htaccess that uses basic authentication. It seems the path to the .htpasswd file isn\'t relative to the htaccess file, but instead to the server config.
So eve
If you are trying to use XAMPP with Windows and want to use an .htaccess file on a live server and also develop on a XAMPP development machine the following works great!
1) After a fresh install of XAMPP make sure that Apache is installed as a service.
- This is done by opening up the XAMPP Control Panel and clicking on the little red "X" to the left of the Apache module.
- It will then ask you if you want to install Apache as a service.
- Then it should turn to a green check mark.
2) When Apache is installed as a service add a new environment variable as a flag.
- First stop the Apache service from the XAMPP Control Panel.
- Next open a command prompt. (You know the little black window the simulates DOS)
- Type "C:\Program Files (x86)\xampp\apache\bin\httpd.exe" -D "DEV" -k config.
- This will append a new DEV flag to the environment variables that you can use later.
3) Start Apache
- Open back up the XAMPP Control Panel and start the Apache service.
4) Create your .htaccess file with the following information...
AuthType Basic
AuthName "Authorized access only!"
AuthUserFile "/sandbox/web/scripts/.htpasswd"
require valid-user
AuthType Basic
AuthName "Authorized access only!"
AuthUserFile "/home/arvo/public_html/scripts/.htpasswd"
require valid-user
To explain the above script here are a few notes...
- My AuthUserFile is based on my setup and personal preferences.
- I have a local test dev box that has my webpage located at c:\sandbox\web\. Inside that folder I have a folder called scripts that contains the password file .htpasswd.
- The first entry IfDefine DEV is used for that instance. If DEV is set (which is what we did above, only on the dev machine of coarse) then it will use that entry.
- And in turn if using the live server IfDefine !DEV will be used.
5) Create your password file (in this case named .htpasswd) with the following information...
user:$apr1$EPuSBcwO$/KtqDUttQMNUa5lGXSOzk.
A few things to note...
- Your password file can be any name you want.
- You should use .htpasswd for security.
- A great password generator found @ http://www.htaccesstools.com/htpasswd-generator/
- A great explanation and reason why you should use that name for your file is located @ http://www.htaccesstools.com/articles/htpasswd/
- MAKE SURE YOU PUT THE PASSWORD FILE IN THE CORRECT LOCATION!!! (See step 4 AuthUserFile area)