要求:
访问
http://www.qq.com/123 url保持不变 显示的结果为指定的404页面
curl -I
http://www.qq.com/123 返回的状态码为404
准备一 404.php页面在最底部加上:
<?php
@header('HTTP/1.1 404 Not Found');
@header('Status: 404 Not Found');
?>
@header('Status: 404 Not Found');
?>
然后nginx里配置
location / {
xxxxx; ##此处表示N多的规则依据实际情况定##
rewrite ^/404.html /404.php last;
if (!-e $request_filename) {
rewrite ^(.*)$ /404.html last;
}
if (!-e $request_filename) {
rewrite ^(.*)$ /404.html last;
}
}
然后reload nginx即可。
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/592247