【发布时间】:2017-12-01 01:19:21
【问题描述】:
我在 Apache 上有虚拟主机,其配置类似于以下内容:
<VirtualHost *:80>
DocumentRoot "/home/doe/www/factory/public"
<Directory "/home/doe/www/factory/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
ServerName doe.example.com
ServerAlias qa.dev
ServerAlias doe202.ddns.net
ErrorLog "/home/doe/logs/doe.log"
CustomLog "/home/doe/logs/aq-access.log" common
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/doe/www/factory/public"
<Directory "/home/doe/www/factory/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
ServerName doe.example.com
ServerAlias qa.dev
ServerAlias doe202.dddns.net
ErrorLog "/home/doe/logs/doe.log"
CustomLog "/home/doe/logs/aq-access.log" common
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/doe.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/doe.exmple.com/privkey.pem
</VirtualHost>
我需要实现的是仅将http://doe.example.com 重定向到https://doe.example.com,当然要附加任何URI。
我已尝试查找该问题的this answer:http to https apache redirection,但它会将所有主机重定向到 HTTPS。
我还尝试更改端口 80 虚拟主机中的 serverName 指令,但这将完全阻止使用 http 的用户访问。
【问题讨论】:
-
把重写放在
-
@ShingLam 注意
VirtualHost *:80包含serverAlias,它会给出相同的结果。即所有主机将被重定向到 https。 -
错过了服务器别名。为什么不为所有其他服务器别名设置另一个 VirtualHost *;80
标签: apache .htaccess ssl redirect