Redirect non trailing slash urls to trailing slash urls

#221613
  • Resolved Asjad
    Rank Math free

    I want to Redirect non trailing slash urls to trailing slash urls. how can I do?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ankit
    Rank Math business

    Hello,

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

    To fix the trailing slash you can use the following filter and paste it inside your theme’s function.php file.

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	return trailingslashit( $canonical );
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Asjad
    Rank Math free

    Hi, will it 301 redirect non trailing slash urls to trailing slash urls?

    Ankit
    Rank Math business

    Hello,

    If the page has canonical URL then the filter will simply put slash at the end of the URL inside the source code of the page. If you want to redirect the page from non-slash to slash URL, then you do with the Rank Math redirection module.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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 ‘Redirect non trailing slash urls to trailing slash urls’ is closed to new replies.