0

I am currently using mod_rewrite to redirect all subdomains to https, but multiple sources have suggested that

Using mod_rewrite to do this isn't the recommended behavior. See RedirectSSL

The apache docs suggest Redirect and RedirectMatch:

A common use for RewriteRule is to redirect an entire class of URLs. For example, all URLs in the /one directory must be redirected to http://one.example.com/, or perhaps all http requests must be redirected to https.

These situations are better handled by the Redirect directive. Remember that Redirect preserves path information. That is to say, a redirect for a URL /one will also redirect all URLs under that, such as /one/two.html and /one/three/four.html.

Unfortunately, both of these documents (and anything else I have found) are only considering matching a single domain, rather than all subdomains. RedirectMatch seems like a good candidate for a relatively simple task like this, but I can't seem to get "http" to match as I expect:

RedirectMatch permanent "^http://(.*)$" "https://$1"

My guess as to why that doesn't work is because the redirectMatch is looking for a path and not a URI, but at this point I am stuck. Is it possible to accomplish a redirect of all subdomains to https without mod_rewrite, or is that the best available method?

MaxPRafferty
  • 273
  • 2
  • 6
  • 1
    Are you kidding me with this duplicate flag? The first three words of the title are *without using mod_rewrite*. I literally could not have been more specific about how the mod_rewrite canonical answer is not applicable here. – MaxPRafferty Jan 25 '16 at 17:29

1 Answers1

1

Normally, for sub domains of different VHosts, I append the following line to each.

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

I normally just add one of these for each subdomain. If you have a very large number of sub domains, this method may not be very scalable, but it's simple and gets the job done.

Felix Jen
  • 403
  • 4
  • 17
  • I'm marking this as correct, as given the extent to which people have ignored the specifics of this question it would seem that there is not a (sans-mod_rewrite) alternative to just listing every subdomain as you suggest. Thank you for actually reading! – MaxPRafferty Jan 25 '16 at 18:04