【发布时间】:2018-08-03 00:03:28
【问题描述】:
我希望对我网站的所有访问都强制使用 HTTPS (https://support.google.com/webmasters/answer/6073543?hl=en)。
我还想强制规范 www URL 访问 (https://www.yes-www.org/why-use-www/)
我正在尝试根据 Apache 建议使用重定向指令 https://wiki.apache.org/httpd/RedirectSSL 和 https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost 这样做
我有一个有效的 Lets-encrypt 证书,其中包含 www 和裸域。
我已配置 *:80 和 *:443 VirtualHost 重定向。 /etc/httpd/conf.d/www.example.com.conf:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://www.example.com
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/www.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
SSLCACertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
Redirect permanent / https://www.example.com
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/www.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
SSLCACertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
DocumentRoot "/var/www/html/www.example.com"
</VirtualHost>
<Directory "/var/www/html/www.example.com">
Order allow,deny
Allow from all
</Directory>
如果我指定基本 URL(example.com、www.example.com、https://example.com 等),一切正常。但是,如果我在裸 HTTPS 请求上指定一个页面,则重定向会吃掉根斜线(https://example.com/index.html 变为 https://www.example.comindex.html)。
【问题讨论】:
标签: apache lets-encrypt