Need another .htaccess to create and live site from Git repo

Here's the script:

There is a Git repository that tracks website files, including .htaccess from root. Git repo is tested at the intermediate site and at the production site.

Problem: The website must be password protected (via htpasswd authentication). It also modifies the .htaccess file. Now committing or clicking from the staging environment means that the .htaccess file (which includes password protection for the root directory) is also uploaded to the website live, forcing the website to also request a password.

Now, what should I do? Should I stop tracking .htaccess ? Should I rewrite .htaccess through the hook after receiving (maybe? How?)? Is there any other way to protect the directory without changing .htaccess ? Any other solution?

+7
source share
4 answers

I would choose not to track .htaccess myself.

Possible options:

  • Track .htaccess-prod and .htaccess-stage (more useful if there are more differences, for example, different configuration settings, passwords, etc., if it is only one line, then maybe this is not the best option). Then, whenever you update something, you must do this in both files, and you will also have to remember the copies of the files in two environments as .htaccess manually when they change.

  • Save only one .htaccess-example file, add captures in both the intermediate and live areas (look at the post-checkout and / or after the merge, probably [1]), which in both of them will copy .htaccess-example as local .htaccess whenever changes have occurred, and optionally add a password-protected string in the stage.

[1] haven't used them yet, so I'm a little confused looking at the documentation. As for post-receive, as I understand it, it is executed when the repo is remote when you click on it, and not in the working copy when it is clicked.

+6
source

Here's the answer to the question: set your own .htaccess file name in Dev and do not check it. For example, .htaccess-dev or .htaccess.staging.

You can set this in the vhosts configuration.

http://www.electrictoolbox.com/change-htacces-filename-apache/

If you are using MAMP Pro, you can set the vhost configuration for the local domain.

+2
source

In the case of Git (contrary to Mercurial) you have only one solution: Branching

You should use different branches for Staging and Live with the only difference in content: .htaccess. Not bulletproof with lots of manual work, but it's your choice

+1
source

For deployment, I recommend capistrano , it is a beautiful utility.

-one
source

All Articles