Support » Plugin: Yoast SEO » [Plugin: WordPress SEO by Yoast] Duplicate content issue with 'enforce a trailing slash' a

  • drrxa

    (@drrxa)


    WordPress version: 3.4.1
    WordPress SEO version: 1.2.4

    I did this: Check the “Enforce a trailing slash on all category and tag URL’s” and use pagination for some posts.

    I expected the plugin to do this: Add trailing slash only to categories and tags URLs.

    Instead it did this: Add trailing slash to sub-pages of paginated posts also, this happened lately, which creates two versions of each sub-page in Google index, one with the trailing slash and one without as follows:

    example.com/post/2/
    example.com/post/2

    I am looking for advice here, I am aware that unchecking this option might resolve the issue by creating a 301 redirect from the “/” version to the non-“/” version, but I would prefer keeping the trailing slash for categories and tags and removing it for sub-pages of the paginated articles.

    Thanks.

    http://wordpress.org/extend/plugins/wordpress-seo/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Joost de Valk

    (@joostdevalk)

    Hmm I wonder why it doesn’t add it consistenly for paginanted posts and pages, that’s what it should do.

    Plugin Author Joost de Valk

    (@joostdevalk)

    Fixed for the next release, it won’t add slashed on those anymore 🙂

    drrxa

    (@drrxa)

    Thanks Joost, you are the best 🙂 Waiting for the next release.

    Plugin Author Joost de Valk

    (@joostdevalk)

    You can try the development version if you want to test it. You can download the development version from here, or you can download it directly here.

    drrxa

    (@drrxa)

    Hi Joost, thanks for prompt updating, now the URLs for sub-pages of paginated posts does not have the trailing slash, but the canonical and the rel-next and rel-prev link tags still points to the slash version of the URL.

    URL: http://example.com/post/2
    link rel="canonical" href="http://example.com/post/2/"
    link rel="prev" href="http://example.com/post"
    link rel="next" href="http://example.com/post/3/"

    The Categories and Tags URLs and their link tags are working properly.

    URL: http://example.com/category/first-category/
    link rel="canonical" href="http://example.com/category/first-category/"
    link rel="next" href="http://example.com/category/first-category/2/"

    drrxa

    (@drrxa)

    A temporary solution for the above problem using wpseo filters. I used the following code in the functions.php file:

    // Remove the trailing slash from the canonical URL of the sub-pages of paginated posts
    function remove_canonical_trailing_slash($url) {
    	if (is_singular()) {
    		return untrailingslashit($url);
    	} else {
    		return $url;
    	}
    }
    add_filter('wpseo_canonical','remove_canonical_trailing_slash',10,1);
    
    // Remove the trailing slash from the URL of the next and prev link tags of sub-pages of paginated posts
    function remove_nxtprv_trailing_slash($linktag) {
    	if (is_singular()) {
    		return str_replace('/"', '"', $linktag);
    	} else {
    		return $linktag;
    	}
    }
    add_filter('wpseo_prev_rel_link','remove_nxtprv_trailing_slash',10,1);
    add_filter('wpseo_next_rel_link','remove_nxtprv_trailing_slash',10,1);

    Hope this is helpful.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] Duplicate content issue with 'enforce a trailing slash' a’ is closed to new replies.