WordPress.org

Support

Support » Requests and Feedback » The permalink mod_rewrite code isn’t always right

The permalink mod_rewrite code isn’t always right

  • The generation of the mod_rewrite code is a really neat feature. Unfortunately, the outputted regex isn’t always right for the view by date. If i have
    /archive/%year%/%monthnum%/%day%/%post_id%/%postname%/
    for the virtual structure, the regex is right:
    RewriteRule ^archive/([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([0-9]+)?/?([_0-9a-z-]+)?/?([0-9]+)?/?$ /wp/index.php?year=$1&monthnum=$2&day=$3&p=$4&name=$5&page=$6 [QSA]
    However, if i change that to
    /archive/%year%/%monthnum%/%day%/%post_id%-%postname%/
    (note the dash between post_id and postname), the dash isn’t marked as optional. IE, i get:
    RewriteRule ^archive/([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([0-9]+)?-([_0-9a-z-]+)?/?([0-9]+)?/?$ /wp/index.php?year=$1&monthnum=$2&day=$3&p=$4&name=$5&page=$6 [QSA]
    The bug is there: “/?([0-9]+)?-([_0-9a-z-]+)?” The dash is now absolutely needed for a match. I’m not sure how the regex should be arranged in such cases, so i’ve reverted to slashes there too. I _believe_ marking the – as optional (“-?”) would be enough, and not cause problems with dashes in article names, but i’m not sure.
    Still, WP is a great system! I love how easy it is to adjust it to do exactly what i want. Even when there isn’t an explicit hook, the code is simple enough that it’s not too hard to adapt it ^_^

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘The permalink mod_rewrite code isn’t always right’ is closed to new replies.
Skip to toolbar