1

We deploy the same code with the same .htaccess to Integration, Stage and Production.

I want to require a basic auth on all but the Production server.

They differ in the path, e.g. /data/stage/www/... vs. /data/prod/www/...

MrWhite
  • 12,647
  • 4
  • 29
  • 41
  • 2
    Then don't deploy a .htaccess file at all but mandate authentication from the main apache configuration – HBruijn Feb 01 '19 at 13:49
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask]. – Daniele Santi Feb 01 '19 at 13:53
  • What is the document root in each case? And where is the `.htaccess` file located? – MrWhite Feb 01 '19 at 14:17
  • 1
    Presumably, the hostname also differs for each server? – MrWhite Feb 01 '19 at 17:57

1 Answers1

1

As mentioned in comments, this does sound like something you should be doing in the server config, rather than .htaccess.

However, this can be done in .htaccess using an Apache expression (Apache 2.4+) to test whether the REQUEST_FILENAME server variable does not start with /data/prod/www/ (ie. the request has not resolved to the Production server).

For example:

<If "%{REQUEST_FILENAME} !~ m#^/data/prod/www/#">
    AuthType Basic
    AuthName "Restricted"
    AuthUserFile "/path/to/passwd/.htpasswd"
    Require valid-user
</If>
MrWhite
  • 12,647
  • 4
  • 29
  • 41