最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Category pages resolving with and without category prefix

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论