最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - A clean custom rewrite rule for weekly archives

programmeradmin0浏览0评论

Weekly archives are nearly undocumented, but WordPress can produce them, which I want. Good. But the URLs are ugly, eg. /?m=2020&w=18

This gets partially rewritten to /2020/?w=18 from somewhere but I'd like it if I could get the whole thing cleaned up, say as /2020/week-18.

I can get to /week/2020/18 via:

function custom_rewrite_rule() {
    add_rewrite_rule('^week/([0-9]+)/([0-9]+)/?','index.php?m=$matches[1]&w=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

…but moving the text in, ie. ^/([0-9]+)/week-([0-9]+)/? fails and I just get 404s.

What am I doing wrong? Or is it just conflicting in some way with whatever rule is doing that partial cleanup? And if so is that addressable?

(Yes, I'm flushing the rules via admin between attempts.)

发布评论

评论列表(0)

  1. 暂无评论