Conditional .Htpasswd for Multi-Environment Setups

Published on November 8th, 2009

So a while back i set Chris over at CSS-Tricks some code for his ongoing snippet library project. This is a quick explanation of that code.

<p>
    You see when you are working with a multi-environment setup that is synced via a version control system such as Git or
    Subversion, you need a way to keep your development environments locked down while allowing access to your public
    environment.
</p>

<p>
    Below is some text that you will input into a .htaccess file placed in your webroot
</p>

<script src="https://gist.github.com/1397070.js?file=gistfile1.txt"></script>

<p>
    so in the above code the "testing_uri" part could be if i only wanted to allow this url through my htaccess protections
    (useful for paypal pings) ex "http://mysite.com/paypal/ipn"
</p>

<p>
    The host part is to allow anyone through if they are requesting the code from a specific domain such as
    "testing.yoursite.com". If it is "development.yoursite.com" it will not allow the user through.
</p>

<a href="http://css-tricks.com/snippets/htaccess/allow-single-url/" target="_blank">here is the code on css-tricks</a> and
<a href="http://gist.github.com/229178" target="_blank">here is the code as a github gist</a>

<p>
    Thanks for reading and as always comments &amp; questions are heavily encouraged!