categories - Category pages resolving with and without category prefix

My website has duplicate content as the category pages are found both with and without the category prefix. I'm not

My website has duplicate content as the category pages are found both with and without the category prefix. I'm not trying to strip the /category part - just trying to figure out why the pages load without it and how to stop it. Every time I google the issue it's all about removing it.

I'm using The SEO Framework Plugin - perhaps that's involved

My website has duplicate content as the category pages are found both with and without the category prefix. I'm not trying to strip the /category part - just trying to figure out why the pages load without it and how to stop it. Every time I google the issue it's all about removing it.

I'm using The SEO Framework Plugin - perhaps that's involved

Share Improve this question asked Jul 27, 2019 at 17:31 bdmasonbdmason 101
Add a comment  | 

1 Answer 1

Reset to default 0

I didn't find the cause. But I was able to hack a solution into functions.php:

add_action("wp", "disable_duplicate_categories");

function disable_duplicate_categories() { 
    if (is_category()) {
        $urlParts = explode('/', $_SERVER["REQUEST_URI"]);
        if ($urlParts[1] !== 'category') {
            array_splice($urlParts, 1, 0, 'category');
            $url = implode('/', $urlParts);
            header("Location: ".$url,TRUE,301);  
            exit;
        }
    }
}

The unwanted pages are never linked to, so the slight delay from redirecting after some of the server code runs and calls the database is unimportant.

I have some code in the theme that's dependent on The SEO Framework, so ruling that out wasn't possible without a lot of messing about. If anybody has a clue as to why the category archives resolve without the category base please share.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745290826a4620846.html

相关推荐

  • categories - Category pages resolving with and without category prefix

    My website has duplicate content as the category pages are found both with and without the category prefix. I'm not

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信