Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a current project we have separate development and production. The code on both is in single SVN repository.

The problem lies in the access to the development environment from outside. Let's say we have two separate servers for prod and dev: -> production -> development

The idea is to use the same .htaccess with Auth on both servers, but the behavior must be:

  • On Development server, the user must Auth himself before accessing the site
  • On Production server, the user has full access, without Auth.

It should be something like this (pseudo code):


We are trying to achieve this with the least possible amount of additional modules, but sadly we couldn't find any information on how to do a condition in .htaccess, based on the server information.

Is it even possible?

share|improve this question
How can you use same .htaccess file for multiple servers? – quanta Nov 9 '11 at 17:00
@quanta: by copying it :) – sysfault Nov 9 '11 at 17:16
Why not create two separate files? – quanta Nov 9 '11 at 17:20
the source code is kept in svn; once testing is OK on dev, bisko commits the changes to svn then updates the production from the same svn server. so instead of branching and merging there goes the multipurpose htaccess file – sysfault Nov 9 '11 at 17:27
Basically what sysfault said. Both dev and production are working copies of the repo and it's just a "svn commit / svn update" away to deploying the new version of the project. – bisko Nov 10 '11 at 12:36
up vote 2 down vote accepted

you should add these to your .htaccess authentication/authorization directives.

setenvif Server_Addr= okpublic
allow from env=okpublic
require valid-user
satisfy any

if the server address is then we set an environment variable that we will use on the second line to allow access to anyone. if server address is not then users must authenticate. if any of these 2 rules are satisfied then access is granted.

what I did is weird but oh well, if this is what you want :)

another solution, much more simpler would be to ignore the .htaccess file when doing svn update on the production server, using svn propedit svn:ignore. if you need to have different .htaccess file on prod and dev then maybe you want to look into branching, merging, etc. or maybe the multi-purpose .htaccess file is just better. I felt like mentioning svn controls as well.

share|improve this answer
that is pretty cool, will keep that in mind for making dev/production configs in future. – Tom H May 13 '12 at 9:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.