Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess password protect but not on localhost

I have set up a dev site and want to password protect it so only validated visitors can view the site. All well and good. I am getting annoyed, on my local version, entering my username and password. So, without changing the htaccess file between my local copy and the one on the dev site, how do I password protect the site but allow myself access without having to enter my username and password?

like image 721
Richard Parnaby-King Avatar asked Dec 01 '10 11:12

Richard Parnaby-King


4 Answers

Something like this should do the trick..

Require valid-user
Allow from 127.0.0.1
Satisfy Any

From: http://httpd.apache.org/docs/2.0/mod/core.html#satisfy

like image 177
Ben Avatar answered Nov 15 '22 22:11

Ben


I've figured out a cool way to seperate Linux from Windows password files (because I develop in windows and then release to a linux production server).

I just wrote a php script with phpinfo(); on our local and prod server and found the apache module 'mod_win32' to seperate the two of them.

<IfModule mod_win32.c>
    AuthUserFile C:\xampplite\your\windows\path.passwd
</IfModule>
<IfModule !mod_win32.c>
    AuthUserFile "/your/linux/path/.passwd"
</IfModule>
AuthName "Please Login"

RewriteEngine On
AuthType Basic
Require valid-user
like image 24
Luc Avatar answered Nov 15 '22 23:11

Luc


Example for Windows:

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile C:/Apache24/htdocs/.htpasswd
Require valid-user
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Satisfy Any
like image 2
Chris Hucke Avatar answered Nov 15 '22 21:11

Chris Hucke


Presuming that you are fine entering the password on the dev site - put the auth directives in a VirtualHost on the dev site rather than in the .htaccess file - this way your auth is processed at a server level rather than a directory level.

Also, most modern browsers will probably save your password for you :)

like image 1
David Miller Avatar answered Nov 15 '22 21:11

David Miller