【发布时间】:2018-11-15 11:21:09
【问题描述】:
在我的 Apache 配置中,所有内容都重定向到 HTTPS(这很好)。但是https://www.example.com 和https://example.com 仍然存在。
问题:如何只有https://www.example.com而不是非www?
我应该使用301 Redirection 还是其他技术?
这样的配置应该怎么改:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /home/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
</IfModule>
?
【问题讨论】:
标签: apache http https virtualhost no-www