Category pages without trailing slash have canonical meta with slash

#634632
  • Resolved Premier Range
    Rank Math free

    Hi guys, sorry if this has been covered elsewhere, I’ve done a lot of searching and found similar issues but can’t figure this one out.

    One our blog at https://www.oursite.com/blog we have tagged our blog posts, which results in category pages being created such as https://www.oursite.com/blog/category/lifestyle (note, no trailing slash). This is how we want it, we don’t want to add any trailing slashes anywhere.

    ahrefs is complaining that our site contains “Canonical points to redirect” as in the image https://imgur.com/a/jOe93iN

    The page was “first found at” the sitemap generated by Rank Math https://www.oursite.com/blog/category-sitemap.xml but this is fine, the URL there has no trailing slash. The problem appears when actually visiting the page, its canonical meta tag has a trailing slash, but visiting that URL returns a 301 redirect to the page without a trailing slash.

    Our Permalink settings are simple, with a Custom Structure selected of /%postname% and blank Category base and Tag base, but I don’t know if they effect this issue or not.

    I ran into a similar problem with trailing slash on the home page, which was solved using the Snippet at https://support.rankmath.com/ticket/wrong-canonical-url-on-home-page/ using add_filter Snippet using 'rank_math/frontend/canonical', maybe a similar trick can be used to fix this canonical meta tag on Category pages.

    I was very impressed with the way you guys have helped others with these fine details, I hope you can help me out 🙂
    Nick

Viewing 2 replies - 1 through 2 (of 2 total)
  • Edit: I also found that Post list pages such as https://www.oursite.com/blog/page/2 contain similar canonicals, i.e.:

    <link rel="canonical" href="https://www.oursite.com/blog/page/2/">

    I’ve no idea if these are the same root cause as the original problem of Category list pages. It seems a similar area but may be slightly different.

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    We’ve checked your site, and indeed the canonical is happening on your category page only.

    In this case, you can try to apply this filter to remove the trailing slash:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
        $canonical = untrailingslashit($canonical);
        return $canonical;
    });

    And here’s a guide on how you can add a filter to your website:
    https://rankmath.com/kb/filters-hooks-api-developer/

    Let us know how this goes.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Category pages without trailing slash have canonical meta with slash’ is closed to new replies.