0

I own secure site https://example.com.

I want to redirect all URLs http://whatever.example.com and https://whatever.example.com to the correct URL https://example.com.

This is my apache2 config:

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

<VirtualHost *:443>
    ServerName x.example.com
    ServerAlias *.example.com
    Redirect 301 / https://example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    Redirect 301 / https://example.com
</VirtualHost>

This works fine with http://whatever.example.com: Apache handles the request and redirects to the correct URL. However, there is a problem with https://whatever.example.com. At least on Chrome, I first get warning that this site is not secure (obviously, there is no ssl certificate for whatever.example.com), and only when I force the browser to load that page, only I get redirected.

So, is there a better redirect than what I am using right now? One that would not confuse user with strange browser warnings.

  • 1
    You must add those subdomains to your TLS certificate. – Michael Hampton Sep 28 '18 at 17:36
1

You either need a wildcard certificate for the domain, or a SAN certificate for the subdomains that you plan to redirect.

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.