虚拟主机中的一个特定的子域不redirect,但是其他的成功

我喜欢我的网站可以通过example.orghttps://example.org而不是www.example.org

所以我希望http://www.example.orgredirecthttp://example.orghttp://www.example.orghttps://example.org

但有趣的事情发生:

https://www.example.orgredirect到https://example.org 而不是http://www.example.orghttp://example.org

我的main.conf:

 <VirtualHost *:80> ServerName example.org ServerAdmin webmaster@localhost DocumentRoot "/var/www/html" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> <VirtualHost *:443> ServerName example.org ServerAdmin webmaster@localhost DocumentRoot "/var/www/html" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /pathtocert.pem SSLCertificateKeyFile /pathtokey.pem </VirtualHost> <Directory "/var/www/html"> Options FollowSymlinks ExecCGI AllowOverride None Require all granted </Directory> 

我的www.conf:

 <VirtualHost *:80> ServerName www.example.org ServerAdmin webmaster@localhost DocumentRoot "/var/www/html" RedirectPermanent / http://example.org ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> <VirtualHost *:443> ServerName www.example.org ServerAdmin webmaster@localhost DocumentRoot "/var/www/html" RedirectPermanent / https://example.org ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /pathtocert.pem SSLCertificateKeyFile /pathtokey.pem </VirtualHost> <Directory "/var/www/html"> Options FollowSymlinks ExecCGI AllowOverride None Require all granted </Directory> 

那么问题似乎是什么? 也不应该都httphttpsredirect失败或一起成功?

问题是域名的DNS“A”和“AAAA”logging。 有一个预先configuration的A / AAAAlogging是造成所有问题的www 。 我删除了它们,并添加了一个新的*.example.org 。 DNS将所有通配符子域redirect到服务器。 现在在networking服务器上负责处理这些问题。

现在工作正常。

还请检查: 如何将所有通配符子域redirect到特定的子域? 与运行下一个云服务器的子域有问题

你可能想要设置一个重写,你可能想要这样的东西:

<VirtualHost *:80> RewriteEngine On # this redirect only www.example.org to https RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www.example.org [NC] RewriteCond %{HTTP_HOST} ^example.org [NC] # this redirects anything to its https equivalent RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L] </VirtualHost>

或者,我想你应该简单地将你的redirect规则修改为从RedirectPermanent / http://example.orgRedirectPermanent / https://example.org 。 redirect必须指向https,而不是http …