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

url rewriting - Need help with regex

programmeradmin1浏览0评论

I have this definiton to add a query var:

add_filter( 'query_vars', 'add_reg_query_vars', 10, 1 );
function add_reg_query_vars($vars)
{   
    $vars[] = 'seminar'; //
    return $vars;
}

and this definition to add a rewrite rule:

add_rewrite_rule(
            '^seminare/([a-zA-Z0-9]+?)/([^/]*)/?$',
            'index.php?pagename=seminare/$matches[1]&seminar=$matches[2]',
            'top'
            );

Like this it is working well, links like /seminare/mysite/123/ are matched, but because I have on same page 'seminare' a pagination, I need to exclude the word 'page', that a link like seminare/page/2 is
not matched by my regex above.

Can't get it to work, and honestly I'm not very experienced with the usage of regex. Tried several expressions and when I use for example:

^seminare/(?!page).+?/([^/]*)/?$

or

^seminare/(?!page)([a-zA-Z0-9]+?)/([^/]*)/?$

which matches in reg-tester it doesn't work in wordpress (tested with monkeyman rewrite analyzer). Links like seminare/page/2/ are not matched anymore, that's good, but a link like above like /seminare/mysite/123/ aren't matched anymore as well.

Would be all happy about some assist in that!!!!

I have this definiton to add a query var:

add_filter( 'query_vars', 'add_reg_query_vars', 10, 1 );
function add_reg_query_vars($vars)
{   
    $vars[] = 'seminar'; //
    return $vars;
}

and this definition to add a rewrite rule:

add_rewrite_rule(
            '^seminare/([a-zA-Z0-9]+?)/([^/]*)/?$',
            'index.php?pagename=seminare/$matches[1]&seminar=$matches[2]',
            'top'
            );

Like this it is working well, links like /seminare/mysite/123/ are matched, but because I have on same page 'seminare' a pagination, I need to exclude the word 'page', that a link like seminare/page/2 is
not matched by my regex above.

Can't get it to work, and honestly I'm not very experienced with the usage of regex. Tried several expressions and when I use for example:

^seminare/(?!page).+?/([^/]*)/?$

or

^seminare/(?!page)([a-zA-Z0-9]+?)/([^/]*)/?$

which matches in reg-tester it doesn't work in wordpress (tested with monkeyman rewrite analyzer). Links like seminare/page/2/ are not matched anymore, that's good, but a link like above like /seminare/mysite/123/ aren't matched anymore as well.

Would be all happy about some assist in that!!!!

Share Improve this question asked May 11, 2020 at 13:45 Joe LippsJoe Lipps 91 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

It's not understandable for me, but the second definition works now. No idea, why it didn't work before, but I guess, somewhere I made a small mistake. Sorry, for my useless post ;)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论