【发布时间】:2017-10-18 14:22:30
【问题描述】:
我的域名是 example.com,没有 www。因此,如果我输入 www.example.com 则它不起作用,但 example.com 有效。所以我这样配置apache
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAdmin webmaster@example.com
DocumentRoot path/to/project/public
SSLEngine on
SSLCertificateFile /path/to/keys/xxx.crt
SSLCertificateKeyFile /path/to/keys/xxx.key
ErrorLog /var/log/apache2/error_log
CustomLog /var/log/apache2/access_log combined
<Directory "path/to/project/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
现在,如您所见,我将永久重定向到 https,例如
Redirect permanent / https://example.com/
但是这个重定向默认会加上域名的www。所以重定向的 url 变成了https://www.example.com/。显然,我的网站无法通过 www 访问,因为它是在没有 www 的情况下注册的。所以请告诉我如何使重定向工作并在没有 https 的情况下转到 https://example.com/。
【问题讨论】: