码迷,mamicode.com
首页 > Web开发 > 详细

百度单方面修改网站url导致大量404

时间:2015-11-12 18:26:24      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

    百度抓取到的内容,用户搜索并访问后,百度改写了url(域名之后的第二个目录),导致出现大量的404,交涉无果,没办法,只能自己修复

1、需求:

        百度给出的url                                                                                正确的url
http://g.perofu.com.cn/x/222/1112345.html      —301——》 http://g.perofu.com.cn/x/111/1112345.htm

    将文章id的前三位数,rewrite到x之后的目录,即不管x之后的第一个目录是什么,都换成文章id的前三位数

2、网站文章规则:
http://g.perofu.com.cn/x/{文章id减后4位}/{文章id}.html

3、错误配置:
#此location,只是做了upstream,url不会变,也可以拿到数据,这样对seo有影响
location ~ ‘^/x/([\d]{3})/([\d]{3})([\d]{4})\.html$‘ {
          rewrite ‘‘^/x/([\d]{3})/([\d]{3})([\d]{4})\.html$‘‘       /wap/x/$2/$2$3.html   break;
          proxy_set_header Host ‘g.perofu.com.cn‘;
          proxy_next_upstream http_502 http_504 error timeout invalid_header;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_redirect      off;
          proxy_connect_timeout 10;
          proxy_read_timeout 60;
          proxy_pass http://WAPATS;
     }

 4、正确配置:

(由于文件不在同个应用下,所以有点麻烦,可能有点乱,主要还是看location吧)

                client     ---> 

                     | 

本机([公网:g.perofu.com.cn],location修改url,再upstream 到ATS)

                     |

                 其他机器

(g.perofu.com.cn仅是虚拟主机,需要配置location,确定文件路径,否则会报404,/data/www/web/3g/是g.perofu.com.cn的主目录且没有其他location,除了/,需要新加上location,把root写为/data/www/web/3g/wap/,用上面的方法,rewrite是有加上/wap的,301只是改写url,请求到其他机器是无法找到url的,因为少了一层目录)

#http://g.perofu.com.cn/x/222/1112345.html   --->   http://g.perofu.com.cn/x/111/1112345.html
#upstream后端需要增加location,把root写为/data1/www/web/3g/wap/,否则报404
location ~ ‘^/x/([\d]{3})/([\d]{3})([\d]{4})\.html$‘ {
                set $dir1 $1;
                set $dir2 $2;
                set $file3 $3;
                if  ( $dir1 != $dir2 ) {
                    rewrite ^/x/(.*)  http://g.perofu.com.cn/x/$dir2/$dir2$file3.html permanent;
                }
          proxy_set_header Host ‘g.perofu.com.cn‘;
          proxy_next_upstream http_502 http_504 error timeout invalid_header;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_redirect      off;
          proxy_connect_timeout 10;
          proxy_read_timeout 60;
          proxy_pass http://WAPATS;
     }    


#其他机器
server {
    server_name g.perofu.com.cn;
    set $adddir ‘/3g‘;
    root /data/www/web$adddir;
    access_log /data/nginx/logs/3g.access.log tpynormal;

#g.pconline.com.cn,301,需要加上,可查看前端的location ~ ‘^/x/([\d]{3})/([\d]{3})([\d]{4})\.html$‘
location ~  ‘^/x/([\d]{3})/([\d]{3})([\d]{4})\.html$‘ {
         root /data/www/web/3g/wap/;
}

}

百度单方面修改网站url导致大量404

标签:

原文地址:http://my.oschina.net/fufangchun/blog/529536

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!