admin管理员组

文章数量:1418700

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.

本文标签: categoriesCategory pages resolving with and without category prefix