URL’s in sitemap have trailing slash

#89308
Viewing 3 replies - 1 through 3 (of 3 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You could add the following filter to your functions.php file (at the end) to force removing all the trailing slashes:

    add_filter( β€˜rank_math/sitemap/entry’, function( $url, $type, $object ){
    $url[β€˜loc’] = untrailingslashit( $url[β€˜loc’] );
    return $url;
    }, 10, 3 );

    Make sure to clean your cache and resave the permalinks (just press the save button) so the sitemaps are regenerated.

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hi Alberto

    Thanks for your message

    The problem is the site is not consistent and some URLs have a trailing slash and some do not.

    Would your solution work with this fact in mind?

    Thanks!

    Hello,

    The filter provided should provided should filter all your URLs before adding them to the sitemap to make sure they have the trailing slash removed. Please let us know if it resolves your issue.

    Looking forward to helping you. 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘URL’s in sitemap have trailing slash’ is closed to new replies.