Apache,我为什么要获得重定向循环?

时间:2017-02-24 19:57:44

标签: apache

我有apache 2.4 config:

<VirtualHost *:80>
  ServerName domain.com
  Redirect permanent "/" "http://www.domain.com"
</VirtualHost>

<VirtualHost *:80>
  ServerName www.domain.com
  Redirect permanent "/" "https://www.domain.com"
</VirtualHost>

<VirtualHost *:443>
  ServerName www.domain.com
  DocumentRoot /var/www/domain.com
  SSLEngine on
  SSLCertificateFile    /etc/letsencrypt/live/domain.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
  SSLCertificateChainFile /etc/letsencrypt/live/domain.com/fullchain.pem
</VirtualHost>

我总是从www.domain.com到www.domain.com获得重定向循环。尝试:

<VirtualHost *:80>
  ServerName domain.com
  ServerAlias www.domain.com
  Redirect permanent "/" "https://www.domain.com"
</VirtualHost>

<VirtualHost *:443>
...
</VirtualHost>

无。只有在<VirtualHost *:443>...</VirtualHost>单独离开时才有效。但当然没有http-&gt; https重定向,也没有非www到www。

1 个答案:

答案 0 :(得分:0)

尝试将第一个子句更改为:(我唯一改变的是重定向到https)

<VirtualHost *:80>
  ServerName domain.com
  Redirect permanent "/" "https://www.domain.com"
</VirtualHost>