I have the following code in my .htaccess file
AuthUserFile ./.htpasswd
AuthGroupFile /dev/null
AuthName "Dev Area One"
AuthType Basic
<Limit GET>
require valid-user
</Limit>
This causes a 500 internal server error because Apache says it can't find the file /etc/apache2/.htpasswd. That's because the .htpasswd is in the directory /var/www/html/dev1.staging.com/public_html/.htpasswd and my .htaccess is in /var/www/html/dev1.staging.com/public_html/.htaccess.
Can I replace AuthUserFile ./.htpasswd with AuthUserFile SOMEVARIABLE+.htpasswd so that every time other team members do a git pull origin master to their dev servers, the .htaccess will properly reference the .htpasswd which should be in the same directory as the .htaccess?
This is purely for development purposes only. There are some servers (some of which are shared hosting) where we do not have file writing access to, so we don't know immediately what directory our web projects are served out of, so we don't know ahead of time the absolute directory path to the .htpasswd.
You can use shell environment variable in path to AuthUserFile by using PassEnv directive:
PassEnv HOME
AuthUserFile ${HOME}/.htpasswd
AuthGroupFile /dev/null
AuthName "Dev Area One"
AuthType Basic
<Limit GET>
require valid-user
</Limit>
Above snippet will work only if each user stores .htpasswd directly under $HOME directory.
Related
I'm trying to temporarily password protect my Heorku app with the .htaccess and .htpasswrd files in the root of the app.
I'm getting a 'Internal Server Error' with the following codes and can't figure out where I'm going wrong
.htaccess
AuthUserFile .htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
.htpasswrd (MD5 encrypted)
rob:$apr1$MRsSwhFN$buG0YTSOezeY8YJ32LXnT1
Looks like your path is off.
As of July 2016, some subtle changes are necessary on heroku-php-apache2. Please note that the path to the .htpasswd file no longer contains the www directory and that the .htpasswd file should be in the webroot as well.
Create an .htaccess file in the webroot:
AuthUserFile /app/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
Create a .htpasswd file, also in the webroot:
htpasswd -c .htpasswd [username]
Commit local changes. Deploy to Heroku.
https://gist.github.com/bbrewer97202/3316425
Would it be possible to have the {HTTP_HOST} variable in this path?
Because my htaccess is used for multiple domains and I want to use different passwords for each domain!
AuthUserFile /usr/test/{HTTP_HOST}/.htpasswd
AuthType Basic
AuthName "My Files"
Require valid-user
UPDATE:
I tested the above code and it gives a 500 Internal Server Error (off course the AuthUserFile points to a directory that DOES exist on my server)
Well, I'm trying to secure my xampp with .htaccess and .htpasswd and I don't see a mistake, so do many other developers that I know...
My .htaccess:
AuthName "Protected Area"
AuthType Basic
AuthUserFile C:/xampp/secret/hidden/place/.htpasswd
require valid-user
php_flag register_globals on
My .htpasswd:
wscript:$apr1$Y107OG1n$Ui6D997SqhERXXyV9VBU51
The error is error 500
Anyone?
You should consult your error logfile usually located at: /var/log/apache2/error.log. Without knowing the exact error there's really only speculation as to what might be the issue.
AuthName "Protected Area"
AuthType Basic
AuthUserFile C:/xampp/apache/var/www/site/.htpasswd
Require valid-user
require valid-user should be capital "R"
AuthUserFile is usually located one directory above the web root.
The permissions on the .htaccess and .htpasswd need to be set so that Apache can read them: chmod 0644 .htaccess chmod 0644 .htpasswd
( further reading )
I can't seem to find the proper way to write my .htaccess file. I initially had the file set up to allow access to a directory of files and that worked fine:
AuthUserFile /var/www/html/technical/mep/.htpasswd
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic
Require valid-user
Now what I need to do is add an additional htpasswd file (something like .htpasswd2) and allow those additional user to only be able to access a single file in that directory. How do I edit my current .htaccess file to make this happen?
You can simply use the <FilesMatch> container:
<FilesMatch protected.html>
AuthUserFile /var/www/html/technical/mep/.htpasswd2
AuthGroupFile /dev/null
AuthName "Password Protected Area 2"
AuthType Basic
Require valid-user
</FilesMatch>
And the file "protected.html" would use the .htpasswd2 file.
I have an htaccess to prevent access to a folder.
Howerver, I would like to one subfolder is allowed to be accessed.
Here is my htaccess file. How can I modifiy it to
AuthName "Private Zone"
AuthType Basic
AuthUserFile /vdir/www.web.net/var/www/vhosts/www.web.net/web/folder/.htpasswd
require valid-user
Here is the folder that I want to be not protected
/vdir/www.web.net/var/www/vhosts/www.web.net/web/folder/go/upload/
How can I do this?
Try to create a .htaccess file under ../go/upload/ with the following content:
AuthType None
Require all granted