Nginx环境下WordPress更换固定链接后设置301重定向 -管理资料

管理资料 时间:2019-01-01 我要投稿
【www.unjs.com - 管理资料】

    为更有效的整合资源,诺豆网各位童鞋决定,更改日志的固定链接形式!

    旧的固定链接形式为:

/item/%post_id%.html

    更新为:

/a/%postname%.html

    这样,诺豆网的日志URL将更为人性化,自由度也更高了!

    同时,问题也来了,由于日志URL的变化,之前收录或被转载的日志链接也将失效,为了避免流量的损失和各位童鞋访问的友好性,基于CentOS下的Nginx环境,做了个301永久重定向,希望各位蜘蛛反应给力点儿哈!!

    具体使用的代码如下:

rewrite ^/item/(.*)$ /a/$1 permanent;

    当然你也可以分开写,例如:

rewrite ^/item/([0-9]+).html$ /a/$1.html permanent; #文章rewrite ^/item/category/(.*)$ /a/category/$1 permanent; #目录分类rewrite ^/item/tag/(.*)$ /a/tag/$1 permanent; #tag分类rewrite ^/item/date/(.*)$ /a/date/$1 permanent; #日期分类

    ps. 其中permanent表示返回301永久重定向,游览器访问地址会显示跳转后的URL地址!

    另需注意:上述301重定向代码一定要放在wordpress伪静态规则之前,否则不生效!给个完整示例吧!

server{listen 80;server_name www.nuodou.com;index index.html index.htm index.php default.html default.htm default.php;root /home/nuodou;rewrite ^/item/(.*)$ /a/$1 permanent;#修改固定链接后,做301重定向#wordpress伪静态if (!-e $request_filename){rewrite ^(.+)$ /index.php?q=$1 last;}include none.conf;……此处略去N个字符……}

最新文章
推荐文章