老刘博客laoliublog.cn
建站技术分享站点!
justhost
aws
cdncloud
ptgidc
huocloud
recloud
hncloud

www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法

racknerd

关注老刘博客的读者应该已经发现本站昨天开始本站最新发布的文章链接已经不再以%post_id%结尾而是%post_id%.html,那么是怎么解决已经被搜索引擎收录的文章链接是%post_id%的呢?

毕竟现在搜索引擎生成的快照内容还是以%post_id%结尾的,如果不作处理,打开肯定404。解决办法就是对www.laoliublog.cn/%post_id%做301重定向到www.laoliublog.cn/%post_id%.html处理,本篇文章就将老刘博客的实践过程分享给读者们,以便以后遇到时作参考。

老刘博客在建站初期,有一段时间,文章页面固定链接是设置成www.laoliublog.cn/%post_id%.html,后面觉得太长了,虽然网上说%post_id%.html更利于SEO,最好还是凭着个人喜好,改成了www.laoliublog.cn/%post_id。

这几天在谷歌移动设备适合性测试工具:https://search.google.com/test/mobile-friendly测试文章页面易用性发现,www.laoliublog.cn/%post_id%会报错“网页不适合在移动设备上浏览”,www.laoliublog.cn/%post_id%.html则显示“网页适合在移动设备上浏览”,因为谷歌移动爬虫爬取前者爬出来的页面内容是“You Are Banned”,原因老刘博客也不得而知。(百度站长平台移动落地页检测是正常的)。

以下是谷歌移动设备适合性测试工具部分测试结果图片:

www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法
网页不适合在移动设备上浏览
www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法
网页适合在移动设备上浏览

所以老刘博客立即把文章页面固定链接重新设置成了www.laoliublog.cn/%post_id%.html,并对www.laoliublog.cn/%post_id%作301重定向到www.laoliublog.cn/%post_id%.html处理,以防止搜索引擎快照打开404,并传递页面权重。

修改老刘博客站点固定链接:

www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法

Nginx环境下,配置文件nginx.conf里加以下规则:

    location ~ ^/(\d+)$ 
    {
        rewrite ^(.*)$ $1.html permanent;
    }

Apache环境下,配置文件.htaccess里加以下规则:

    RedirectMatch 301 ^/(\d+)$ $1.html

以上就是老刘博客分享的www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法,如有疑问,欢迎留言。

关于 老刘博客

本站宗旨是为方便站长、科研及外贸人员,请勿用于其它非法用途!站内所有内容及资源,均来自网络。本站自身不提供任何资源的储存及下载,若无意侵犯到您的权利,请及时与我们联系。

未经允许不得转载:老刘博客 » www.laoliublog.cn/%post_id%实现301重定向到www.laoliublog.cn/%post_id%.html方法
在线客服
在线客服
QQ客服