I am trying to fix a setup where people accessed a site via https://subdomain
but we have a proper SSL cert for https://subdomain.domain.tld
.
I am trying to force redirect to https://subdomain.domain.tld
when people navigate to the old URL.
I've tried all sort of variations to no avail. Currently my thinking was something like below:
Note: This seems to work for http --> https but not http(S).
<VirtualHost *:80>
ServerName subdomain.domain.tld
ServerAlias subdomain
RewriteEngine On
RewriteRule ^/?(.*) https://subdomain.domain.tld:443/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName subdomain
Redirect https://subdomain https://subdomain.domain.tld:443/
</VirtualHost>
<VirtualHost *:443>
ServerName subdomain.domain.tld
....
</VirtualHost>
Redirect / https://subdomain.domain.tld/
(HTTP 302) orRedirect permanent / https://subdomain.domain.tld/
(HTTP 301). You don't need to add the port number:443
in both examples as this is the default https port. You could also change theRewriteRule
to aRedirect
in your first vhost and removeRewriteEngine On
.