0

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:

1.2.3.4 -> production
5.6.7.8 -> 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):

IF $SERVER_IP == 5.6.7.8 THEN
    require_auth
ELSE 
    do_not_require_auth

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?

bisko
  • 103
  • 3
  • How can you use same `.htaccess` file for multiple servers? – quanta Nov 09 '11 at 17:00
  • @quanta: by copying it :) – user237419 Nov 09 '11 at 17:16
  • Why not create two separate files? – quanta Nov 09 '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 – user237419 Nov 09 '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

1 Answers1

2

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

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

if the server address is 1.2.3.4 then we set an environment variable that we will use on the second line to allow access to anyone. if server address is not 1.2.3.4 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.

user237419
  • 1,663
  • 8
  • 8
  • that is pretty cool, will keep that in mind for making dev/production configs in future. – Tom May 13 '12 at 09:40