raspbian 在 apache2 上强制使用 SSL 和 WWW

Force SSL and WWW on apache2 for raspbian

当我在下面同时使用 mod_rewrite 和 mod_ssl 时,生成的域是: https://www.domain.com// 我觉得这个额外的 '/' 很烦人,我想去掉它.问题是我编码的方式还是我应该考虑改用 .htaccess?

000-默认值:

<VirtualHost *:80>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^www\.fusioncodes\.com [NC]
        RewriteRule ^(.*)$ https://www.fusioncodes.com/ [R=301,L]
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://www.%{HTTP_HOST}/ [NC,R=301,L]
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin webmaster@localhost

        SSLEngine On
        SSLCertificateFile    ~server.crt
        SSLCertificateKeyFile ~server.key
 ..... More SSL Stuff
 </VirtualHost>

将第 3 行 (RewriteRule) 更改为:

    RewriteRule ^/?(.*)$ https://www.fusioncodes.com/ [R=301,L]

Refer here

RewriteRule ^/?(.*) https://www.%{HTTP_HOST}/ [NC,R=301,L]