• Resolved baldidiot

    (@baldidiot)


    We have an old site that we converted to wordpress, to minimise distruption we kept the old site url structure – meaning that most pages end in .html not /.

    AIO seems to be adding a slash to the end of the URL in the canonical though, for example:

    /this-page.html

    has a canonical of:

    /this-page.html/

    Is there a way to disable this or just disable the canonical URL generation entirely whilst we figure out a solution?

    I know you can edit the individual pages but we have thousands of them.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @baldidiot,

    You should be able to fix this by adding this code snippet to your child theme’s functions.php file –

    add_filter( 'aioseo_canonical_url', 'aioseo_filter_canonical_url' );
    
    function aioseo_filter_canonical_url( $canonicalUrl ) {
    	return untrailingslashit( $canonicalUrl );
    }

    – Arnaud

    Thread Starter baldidiot

    (@baldidiot)

    Thanks. Would this remove all trailing slash from all pages though? Some pages do have a trailing slash (ie: a parent page – it’s an old joomla site converted to WP so the format is /category/ and /category/article.html).

    So we still need:

    /parent/ to return /parent/ as the canonical.

    It’s only where the URL suffix is not / that we would need it removed.

    • This reply was modified 4 years, 2 months ago by baldidiot.
    • This reply was modified 4 years, 2 months ago by baldidiot.
    Plugin Author arnaudbroes

    (@arnaudbroes)

    That would remove it for all URLs unfortunately. Does each of these pages end with .html? I can adapt the snippet so that it only removes the trailing slash for URLs ending with .html.

    Thread Starter baldidiot

    (@baldidiot)

    OK great, thanks – yes the only variation from the slash is if it’s html, so the URLs always either end with ‘/’ or ‘.html’.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘AIO Adding Slash to Canonical When URL Ends in .html’ is closed to new replies.