Created
March 4, 2012 17:33
-
-
Save siffring/1974022 to your computer and use it in GitHub Desktop.
htaccess to password protect a specific server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# Password protect staging server | |
# Use one .htaccess file across multiple environments | |
# (e.g. local, dev, staging, production) | |
# but only password protect a specific environment. | |
# ---------------------------------------------------------------------- | |
SetEnvIf Host staging.domain.com passreq | |
AuthType Basic | |
AuthName "Password Required" | |
AuthUserFile /full/path/to/.htpasswd | |
Require valid-user | |
Order allow,deny | |
Allow from all | |
Deny from env=passreq | |
Satisfy any |
@loekwetzels I think you're missing the vital line in there! This password protects the server, spoofing the domain name won't get around that, you'll still need to know the password.
Hopefully this is help for my staging / development sites.
@elliotlewis - Unfortunately I think that @loekwetzels is right. If you put to your hosts file a record as he describes, then SetEnvIf Host staging.domain.com
returns FALSE
, so env
variable won't be passreq
. Because my host is omgihazaccess
(from @loekwetzels example).
I think @jan-vodila and @loekwetzels are right. Probably not a good solution for anything seriously important
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a nice little trick for basic needs, but it's not very safe as it could easily be spoofed in a few basic steps:
Tada, no password required!
The other way around would be a little safer (require password in all cases, except when using production domain) but could still be spoofed if the attacked pointed the production hostname to the staging server ip address.