Apache重定向无法正常工作

时间:2017-03-09 18:28:38

标签: apache

我在apache .conf文件中有这个:

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/html/example/
    SSLEngine on
    SSLCertificatekeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
<VirtualHost *:443>
Redirect 301 /recalls/recalls.html https://recallpatrol.com/recalls.html
</VirtualHost>

但是没有重定向发生。我试图阻止任何人直接点击recalls,这实际上并不存在。我无法弄清楚它来自何处,所以在此期间,我需要重定向。

1 个答案:

答案 0 :(得分:1)

Apache使用ServerName匹配相应的虚拟主机,但您的第二个虚拟主机定义不包含任何虚拟主机,因此Apache永远不会匹配该虚拟主机,因此完全忽略它。

因此,如果两个虚拟主机属于同一个域,则将它们合并为一个

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/html/example/
    SSLEngine on
    SSLCertificatekeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

    Redirect 301 /recalls/recalls.html https://recallpatrol.com/recalls.html
</VirtualHost>