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/...
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/...
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>