Problem:
You want to have dev.yoursite.com and www.yoursite.com but you don’t want dev.yoursite.com visible to the public.
Solution:
If your using apache(which many of us are),
.htaccess and .htpasswd to the rescue.
In your .htaccess file add:
SetEnvIf Host yourstagingserver.com passreq AuthType Basic AuthName “Staging Server” AuthUserFile /path/to/.htpasswd Require valid-user Order allow,deny Allow from all Deny from env=passreq Satisfy any
Configure your password file on both dev & production
Wherever you specify the /path/to/.htpasswd file navigate to that folder from the console and type “htpasswd -c .htpasswd mark” where mark is the first user you want to create a login for. For each additonal person type “htpasswd .htpasswd linda” where linda is the next username you want to add to the .htpasswd file. Each time it will prompt you to type in the password twice.(your password will be stored in the .htpasswd file) encrypted next to the username you created.
*Note:
AuthUserFile expects an absolute path, but if you don't start your path with a forward slash, it defaults to the directory you specify in your httpd.conf file as ServerRoot.