Apache VirtualHost 配置不会重定向我需要它的方式

Apache VirtualHost config doesnt redirect how i need it to

问题是为什么要重定向 http://www.example.com to https://example.com and why doesn't https://example.com redirect to https://www.example.com?我想将所有人重定向到 https 和 www。我已经尝试了所有我能想到的方法,但似乎没有什么可以解决这个问题。

/etc/httpd/sites-available/example.com.conf
<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    RedirectMatch ^/(.*) https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com
    RedirectMatch ^/(.*) https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    DocumentRoot /var/www/example.com/html
    ErrorLog /var/www/example.com/log/error.log
    CustomLog /var/www/example.com/log/requests.log combined
    SLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com-0001/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0001/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com-0001/chain.pem
    SSLCACertificateFile /etc/letsencrypt/live/example.com-0001/fullchain.pem
</VirtualHost>

conf.d/non-ssl.conf 不正确 :D