且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

nginx特定的 404页面利于seo

更新时间:2022-09-13 23:19:54

要求:
访问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');
?>
 
然后nginx里配置
location / {
       xxxxx;  ##此处表示N多的规则依据实际情况定##
       rewrite ^/404.html /404.php last;
          if (!-e $request_filename) {
            rewrite ^(.*)$ /404.html last;
             }  
          }
      
然后reload nginx即可。

本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/592247