• Resolved chillmen

    (@chillmen)


    Hi,
    I’m trying to add the %post_id% in permalinks and i noticed a strange behavior how wp use the redirect
    Case one:
    using permalink structure: /%post_id%/%postname% (no trailing slash in the end)
    if i type url in browser with only the post name, i’m redirected to /post_id/post_name
    It’s good

    Case two: (the one i want to use)
    using permalink structure:/%postname%/%post_id% (no trailing slash in the end)
    if i type url in browser with only the post name, i’m not redirected to /%postname%/%post_id%
    So my post now can be accesible via url:
    /%postname%
    and
    /%postname%/%post_id%

    Is it normal that the post is not redirected to choosen permalink structure in case 2 ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I can confirm the same behavior on my site. I don’t know if it’s “normal” or not. On one hand, the terms are redundant, one only needs one or the other. OTOH, if the permastruct is set to have both, the redirect should have both IMO. In truth though, as long as the canonical link doesn’t change (it doesn’t), there is no ill effect from this as far as SEO is concerned.

    I believe the behavior is managed by redirect_canonical(), which has a filter of the same name where one can alter default behavior if maintaining the ID is really important to you.

    BTW, you should try to use a trailing slash in all WP permalinks. If you do not, WP will do an extra redirect in order to include it. You should want to avoid unnecessary redirects.

    Thread Starter chillmen

    (@chillmen)

    hi bcworkz,
    Thanks for your reply

    You are right about canonical links

    About the importance of using ID in permalink, i think it is important in my case, because i have thousands of posts, some with near to similar titles and post id makes the url unique. Maybe i’m wrong !

    First i was trying to use a combination of category id and post id like this: %category_id%-%post_id% but wp does not have category ID as an option, i have to add this via a function, i’m not yet ready to make this move.

    Moderator bcworkz

    (@bcworkz)

    Every post’s permalink slug has to be unique anyway. When you try to use an existing slug, WP will append a number to ensure it’s unique. Including the ID is redundant. You don’t really need a reason to want to include the ID, if it’s what you want, you should have it. That said, all the links within your site should already include the ID. It only gets dropped when someone manually types in an abbreviated permalink. If that’s bothersome, filter the “redirect_canonical” to ensure it’s always part of the URL.

    Thread Starter chillmen

    (@chillmen)

    Thank you @bcworkz for your time and help
    I will do some tests

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Permalink with post_id question ?’ is closed to new replies.