On our dev server we have multiple sites for multiple developers running via vhosts in Apache 2.4.6. We are on CentOS 7.
We want to redirect all http://www.site.ext.dev-username.commondomain.ext
to https://www.site.ext.dev-username.commondomain.ext
. Here, dev-username
and site.ext
can change depending on dev site and user.
We have previously used something like this:
<VirtualHost *:80>
ServerName www.site.ext.dev-username.commondomain.ext
Redirect permanent / https://www.site.ext.dev-username.commondomain.ext/
</VirtualHost>
But is it possible to match any (or at least wildcard) ServerName
and redirect accordingly, i.e. with a backreference to a regex? Maybe with a DirectoryMatch
or something instead of the vhost?
I have noticed this in the documentation (for directory and location matching), which is sadly not compatible with my version of Apache:
From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.