Search code examples
git.htaccess.htpasswd

Is it possible to have separate git ignore rules for each remote?


Here's my situation. I'm setting up a development server and a production server on PHP Fog. I have one set of files on my local machine that I'd like to be able to work on and push to each of the 2 servers on PHP Fog.

I want my development server to be protected though, using traditional htpasswd/htaccess methods. This means the production server needs to ignore those two files in my working copy.

Is there a way to tell the production server to ignore those two files when a commit is made but let them go through when pushing to the development server?


Solution

  • I was looking in to this a while back as well and I used this article, it should explain how to use a single htaccess for multiple sites rather than worrying about git.

    Blog post: "Single .htaccess file in your git repo for both your dev and production server" by Mark Alan Evans

    He described the problem thusly:

    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.