How to redirect all non-www traffic to the www version?

Hi,

first of all i wanted to let you know that i could never install a SSL cert so flawlessly befor. I :heart: Let’s Encrypt!

There is only one thing left which i could not solve.

I created a cert for mydomain.tld and www.mydomain.tld and opted in for “Secure - Make all requests redirect to secure HTTPS access” . This works like a charm.

But i also want the non-www calls get redirect to the www-version. How can i modify the Apapche Config to achieve that?

Thank you!

The way I use is to create another virtual host containing the redirect rule, like this:

<VirtualHost *:443>
        ServerName domain.tld
        Redirect "/" "https://www.domain.tld/"

        SSLEngine on
        SSLCertificateFile    /etc/letsencrypt/live/domain.tld/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/domain.tld/chain.pem
        SSLUseStapling on
</VirtualHost>

Then the same on port 80 but without the SSL lines.

1 Like