0

I placed the following config in apache site conf file:

<VirtualHost *:80>
        ServerName domain.com
        ServerAlias *.domain.com
        ServerAdmin webmaster@localhost
        Redirect permanent / https://domain.com/
</VirtualHost>

How can I have subdomains redirect without going to the main domain?

If I type http://subdomain.domain.com/ it redirects to https://domain.com/ but I want it to redirect to https://subdomain.domain.com/. I also want it to be a wildcard so that it works for all subdomains.

Is it possible without engaging the mod_rewrite module?

ADTC
  • 8,999
  • 5
  • 68
  • 93
  • 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:34

1 Answers1

0

I don't think it's possible without mod_rewrite, but I'm not sure. With rewrite is very simple though:

RewriteEngine On

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
palako
  • 3,342
  • 2
  • 23
  • 33