找不到的页面重定向到404页面 - 不发出404代码

时间:2017-09-01 09:53:42

标签: apache http-status-code-404

我认为我有一个错误配置的apache指令或两个。

如果您访问此页面:

http://www.rgraph.net/blog/new-line-chart-trace-effect-using-the-clip-canvas-method.html

它重定向到404页面并在地址栏中显示404页面的地址,这是:

https://www.rgraph.net/404.html

我非常确定这些Apache指令应该受到指责,因为如果你转到页面的HTTPS版本它会正常工作(显示404页面,同时在地址栏中保留原始地址)。像这样:

https://www.rgraph.net/blog/new-line-chart-trace-effect-using-the-clip-canvas-method.html

这是我认为错误的Apache指令:

RewriteCond %{HTTP_HOST} ^www.rgraph.net$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

对于存在的地址,它可以正常工作。例如:

http://www.rgraph.net/blog/index.html

该地址正确地重定向到页面的HTTPS版本。

1 个答案:

答案 0 :(得分:0)

我通过更改重写来处理除HTML文件之外的所有内容,然后PHP(解析我服务器上的HTML文件)处理这些文件的重定向。所以这现在正确显示404消息,同时仍保留地址栏中的地址:

http://www.rgraph.net/blog/new-line-chart-trace-effect-using-the-clip-canvas-method.html

以下是我正在使用的修改后的Apache配置:

RewriteCond %{HTTP_HOST} ^www.rgraph.net$
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !(\.html)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]