WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
Duplicate content issue with 'enforce a trailing slash' a (7 posts)

  1. drrxa
    Member
    Posted 2 years ago #

    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/

  2. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

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

  3. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    Fixed for the next release, it won't add slashed on those anymore :)

  4. drrxa
    Member
    Posted 2 years ago #

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

  5. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  6. drrxa
    Member
    Posted 2 years ago #

    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/"
  7. drrxa
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.