1

I'm using apache 2.4

I would like to redirect any HTTP traffic to HTTPS matching any canonical domain of the apex domain. I know it's possible to do it via RewriteRules but I would like to use RedirectMatch instead, where it takes the domain name from the HTTP header.

ServerName exampledomain.com
ServerAlias *.exampledomain.com
<If "%{SERVER_PROTOCOL} != 'HTTPS'">
RedirectMatch (.*) "https://%{HTTP_HOST}$1"
</If>

So when you ask for http://anynameyoucanimagine.exampledomain.com it redirects you to https://anynameyoucanimagine.exampledomain.com.

Any ideas ?

Thanks a lot !

2

the following lines should be simply enough

ServerName anynameyoucanimagine.exampledomain.com
RedirectMatch /(.*) https://anynameyoucanimagine.exampledomain.com/$1
  • Yeah, but I can't have it hard written, there are hundreds of subdomain names which I need to match. – DaWe4444 Oct 2 '17 at 14:33
  • if %{HTTP_HOST} variable does not work, you may need to use mod_rewrite as explained here stackoverflow.com/questions/23059463/… – lese Oct 2 '17 at 14:37
  • Yes, that's why I'm asking if anyone has any idea solving it via RedirectMatch. Also mod_rewrite is slower then redirect. – DaWe4444 Oct 2 '17 at 14:48
  • Since I think there is not a possible way to do it one line using RedirectMatch, and you do not want to use mod_rewrite because its less performant, I think you have to repeat the above lines or similar, for all the hundreds VHosts. Or better, I think you will have to give up and use mod_rewrite at the end – lese Oct 2 '17 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.