• Resolved FrederikDussault

    (@frederikdussault)


    Hello everyone,

    Could someone explain me the mechanics of post_link filter and rewrite rules?

    Once the permalink is modified through a post_link filter, is the updated permalink be passed through the rewrite rules again?

    Considering these rules

    $regex = '/dl/.*/?';
    rewrite = 'index.php?pagename=dl';
    add_rewrite_rule( $regex, $rewrite, 'top' );
    
    $regex = '/(en|fr)/dl/.*/?';
    rewrite = 'index.php?pagename=dl&lang=$matches[1]';
    add_rewrite_rule( $regex, $rewrite, 'top' );

    The URL is http://www.next.ca/dl/aa/aa/00/ri/00/?lang=fr
    with a post_link filter, the updated permalink is
    http://www.next.ca/fr/dl/aa/aa/00/ri/00/?lang=fr
    (You will recognize Polylang’s doing)

    Will the updated permalink be passed through the rewrite rules again and be caught by second rule (and index.php?pagename=dl&lang=fr be served)?

    Or is it another mechanism?

    Thanks in advance for your explanations.

    https://wordpress.org/plugins/rewrite/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter FrederikDussault

    (@frederikdussault)

    I have found this article http://code.tutsplus.com/articles/the-beginners-guide-to-wordpress-actions-and-filters–wp-27373 that helped me to understand a little bit how WordPress loads.

    Unfortunately it does not explain if there is a check to see if the newly updated permalink (though a ‘post_link’ rule) would match another rewrite rule (other than the originaly caught one).

    Thanks in advance,

    Thread Starter FrederikDussault

    (@frederikdussault)

    After a few tests I may say the updated permalink is passed to server rewrite rules again.

    Please note the order of your rewrite rules. The more specific one, or ones not needing extra process, should be listed first.

    In my case, I should have listed

    $regex = '/(en|fr)/dl/.*/?';
    rewrite = 'index.php?pagename=dl&lang=$matches[1]';
    add_rewrite_rule( $regex, $rewrite, 'top' );
    
    $regex = '/dl/.*/?';
    rewrite = 'index.php?pagename=dl';
    add_rewrite_rule( $regex, $rewrite, 'top' );

    The first rule would be picked up only once the second rules would have been fired, the permalink processing&update done.

    Please not I am still interested to know about WordPress mechanism. 🙂

    Marking the post as resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘post_link filter and rewrite rules’ is closed to new replies.