apache2 重定向不起作用

apache2 重定向不起作用

这是我的配置:

<VirtualHost *:80>
    ServerName example.com
    Redirect / https://example.com/
    ServerAdmin [email protected]
    ServerAlias www.example.com
</VirtualHost>

它应该将用户重定向到https://example.com,但它不起作用。我使用这个配置已经一年多了,它起作用了,但现在当我尝试访问http://example.com,其显示以下错误:

Not Found
The requested URL / was not found on this server.

当我输入http://www.example.com,apache 正确重定向请求。任何其他重定向到不同的虚拟主机也正常工作。我使用的是 Apache/2.4.7(Ubuntu 14.04)。

答案1

您可以尝试下面提到的不同顺序,除此之外,您的重定向似乎是永久的,因此您可以让搜索引擎知道这一点:

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

在我们这样做的时候,一个经常被忘记的事情是重定向https://example.comhttps://www.example.com如果符合标准或反之亦然,如果您更喜欢使用不带 www 的域名作为主要域名。

相关内容