研究wordpress固定链接

没事折腾wordpress,改了固定链接,发现全成了404,网上百度一番,基本搞定,现记录下来,方便以后使用。

wordpress固定链接的基本形式有以下几种:

1、 /%year%/%monthnum%/%day%/%postname%/

2、 /%year%/%monthnum%/%postname%/

3、 /%year%/%monthnum%/%day%/%postname%.html

4、 /%year%/%monthnum%/%postname%.html

5、 /%category%/%postname%.html

6、 /%post_id%.html

7、 /%postname%/

我改成这种形式:

/%category%/%post_id%.html

改了固定链接,直接访问肯定会出现404。由于我用的nginx,所以也要改rewrite规则,规则如下:

if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}

加载了上述规则后,页面就可以正常访问,但是登录后台却不行了,成了404,吓我一跳。又百度一番,发现改了固定链接会影响到后台页面,所以还需要加一段规则:

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

再次重新加载Rewrite规则,前台和后台访问已经全部正常了。

后续又查了下,貌似这个规则官方有更新了,两行就可解决,换成这个试了试,也确实是正常的。

location / {
try_files $uri $uri/ /index.php?$args;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}

在使用中发现,栏目页面的链接是:URL/category/栏目名。我想去掉其中的“category”,变成“URL/栏目名”的形式,发现只需要在后台做一个小小的改动就行了。在后台的“固定链接”页面,将“分类目录前缀”中填上“.”,也就是英文中的句号,保存即可。

  • 用支付宝打我
  • 用微信打我

生活是一种记录:记录所见、所闻、所想、所感……

《研究wordpress固定链接》25条评论

  1. 隔音屏障 说道:

    不错的文章,内容文章雅致.禁止此消息:nolinkok@163.com

  2. 胶管 说道:

    不错的文章,内容妙趣横生.禁止此消息:nolinkok@163.com

  3. 防风抑尘网 说道:

    好文章,内容出神入化.禁止此消息:nolinkok@163.com

发表评论

【取消回复】