4

I am trying to redirect HTTP traffic to HTTPS on my server.

I have certificates for this.example.net, that.example.net and etc.example.net, and I have my DNS accepting wildcards. I would like to permanently redirect HTTP to HTTPS using a wildcard.

I have tried:

<VirtualHost *:80>
    ServerName example.net:80
    ServerAlias *.example.net
    ServerAdmin mark@example.net
    RedirectMatch 301 (.*) https://$1.example.net
</VirtualHost>

but that doesn’t work.

I know that I can set up individual subdomains this way, but is it possible to use wildcards?

Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40
Manngo
  • 14,066
  • 10
  • 88
  • 110
  • Does this answer your question? [redirect all subdomains from http to https](https://stackoverflow.com/questions/23059463/redirect-all-subdomains-from-http-to-https) – Nux Jul 12 '21 at 19:35

1 Answers1

0

As RedirectMatch Directive of Apache 2.4 httpd says:

Syntax: RedirectMatch [status] regex URL

This directive is equivalent to Redirect, but makes use of regular expressions, instead of simple prefix matching.

Example:

RedirectMatch "(.*)\.gif$" "http://other.example.com$1.jpg"

Apache uses PCRE compatible regexp's.

But normally it should be enought to use:

Redirect permanent / https://www.example.com/

Last but not least the important part: Redirect only matches URL-path and not the complete URL!

So you better add a VirtualHost configuration for every subdomain you are using.

PowerStat
  • 3,757
  • 8
  • 32
  • 57