.htaccess password protect for a specific domain |
[eluser]CroNiX[/eluser]
For a project, I have www.mydomain.com and dev.mydomain.com and I want to use a single htaccess file that will work for both of them, but I want password protection for the dev site. This is so we can use a single .htaccess file in git. if(site_url === 'dev.mydomain.com') { AuthType basic AuthName "Development" AuthUserFile /home/path/.htpasswd Require valid-user } how would you write that in .htaccess? Thanks
[eluser]bretticus[/eluser]
Do... www.mydomain.com and dev.mydomain.com ...point to the same directory and/or virtual host? If they do then you probably can't do this with an htaccess file (at least I know of no way to do a conditional that is a directive allowing host header matching.) Instead, you could detect this in your application and generate the appropriate auth headers via code: http://php.net/manual/en/features.http-auth.php
[eluser]CroNiX[/eluser]
they are actually independent virtual servers, but share a common git repository. Thanks for the PHP reference, I didn't even think to check that side of it lol.
[eluser]bretticus[/eluser]
[quote author="CroNiX" date="1268892936"]they are actually independent virtual servers, but share a common git repository.[/quote] In that case, if you have access to the apache config files (httpd.conf. etc.) than just do the auth configuration for one.
[eluser]CroNiX[/eluser]
Why do you have to make me feel soooo stupid today lol. Oh man, one of those days...
[eluser]bretticus[/eluser]
[quote author="CroNiX" date="1268903395"]Why do you have to make me feel soooo stupid today lol. Oh man, one of those days...[/quote] Well, not too many developers administer Web servers and write code. Fortunately, I'm one of the unfortunate. ![]() ![]() |
Welcome Guest, Not a member yet? Register Sign In |