Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a dev server and live server, both running my site on Apache. In my .htaccess file, in addition to lots of mod_rewrite commands and other important things, I also have Auth access control for the live server. (The dev server is on my local Mac, so I don't need it there...)

Right now it's hard to sync .htaccess up to the live server since I can't just copy my dev .htaccess file (that would overwrite the Auth commands), so I have to manually edit the live one.

Is there a way to have a conditional in the .htaccess file? I'm imagining something like:

<On Live_Server>
  AuthName "Restricted Area"
  AuthType Basic
  AuthUserFile /home/lmiv/.htpasswds/.htpasswd 
  Require valid-user
</on>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Very close, yes. You could use an <IfDefine> block for this. It requires that you start Apache with an additional -D directive, the argument to which then becomes available anywhere in the Apache configuration. For instance, if you add -DLive_Server to the command-line options in production, you could then do this in your configuration in all environments:

<IfDefine Live_Server>
  AuthName "Restricted Area"
  AuthType Basic
  AuthUserFile /home/lmiv/.htpasswds/.htpasswd 
  Require valid-user
</IfDefine>

You could also do the reverse, and define something like -DDev_Server in your development environment, and invert the match:

<IfDefine !Dev_Server>

I prefer the latter, since it requires less "special" configuration for the production environment, and it doesn't require you to restart the production instance just to get the -D added to the command line.

share|improve this answer
    
Perfect. Thanks. –  Eric Mar 8 '12 at 14:33
1  
Is there any way to specify a -D value in the .httpdconf file? –  Eric Mar 8 '12 at 18:04

Your Answer

 
discard

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.