问题
I am using Git on my projects and work in a local virtualbox. The problem I run into is that sometimes the remote .htaccess file contains f.e. a RewriteRule that prevents it from working correctly on a different environment.
Since changes are tracked in Git I cannot simply change the .htaccess on local machine, without having to ignore the changed file state in Git.
I've read here about some setEnvIf solution, but can't really put my finger around it for my own use.
F.e. if I would have in a .htaccess file:
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I want to be able to say:
<if not on local machine>
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
</if>
Or maybe even do something like
If host = dev
...
if host = acc
...
by setting that dev hostname always ends with ".dev" and acc is always like "acc.*"
I would like to have some way to fix it as general as possible so that it's not required to change the lines for each project. .htaccess file should be in version control and should run on each environment without the need to change it. In this example it's a rewriterule, but could also be errordocument or password protection, etc.
Hope I explained my problem clearly. Thanks!
Dennis
回答1:
I have changed my approach. I have been advised that it is unwise to have configuration files forced via a git repo.
I have removed the .htaccess from the repository and ignore this file. I ship an example .htaccess file, f.e. .htaccess-example. On every environment I can copy this file to a .htaccess and then make required local changes.
I will find a way to create a deployscript so I can make changes to .htacces file by copying f.e. a tracked .htaccess-production file to .htaccess.
来源:https://stackoverflow.com/questions/19931799/configure-htaccess-file-for-multiple-environments