On a service available through different subdomains/domains, I want to be able to use only one .htaccess file. For each possible value of %{HTTP_HOST}
, I have set up if
blocks like this:
<if "%{HTTP_HOST} == 'staging.project.example.org'">
[detailed configuration...]
</if>
<if "%{HTTP_HOST} == 'development.project.example.org'">
[detailed configuration...]
</if>
This works well with access configuration lines like:
<if "%{HTTP_HOST} == 'staging.project.example.org'">
AuthType Basic
AuthUserFile ".htusers"
Require user example
Order deny,allow
Deny from all
Allow from xxx.xx.xx.xxx
</if>
But RewriteRule
lines like this will be ignored by Apache:
<if "%{HTTP_HOST} == 'production.project.example.org'">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ https://www.project.example/maintenance.html [R=307,P]
</if>
Is it possible to use RewriteRule
with if
in .htaccess? I think it might be because of
"Only directives that support the directory context can be used within this configuration section."
in https://httpd.apache.org/docs/2.4/en/mod/core.html#if
but is there a way around this?