1

On my WordPress site, I have this URL format:

/%category%/%postname%/

When I create a new post and select a parent category and a sub-category and select sub-category to default then WordPress builds a URL that looks like this:

/parent-category/sub-category/postname1

This URL and the top URL:

/parent-category/postname1

are both working correctly and both show that one post.

The problem starts when Google says one of them is a duplicate post.

Now I want to redirect this URL

/parent-category/postname1

to this url

/parent-category/sub-category/postname1

for all posts on the entire site and for future posts.

1

Personal Feeling about Categories in Paths

Personally, I stopped going crazy about categories and actually even removed them completely from my websites. They not only don't help because people don't search those lists (my hits on those lists has always been dismal) but as you can see it creates duplicates. So I deleted all my categories.

As a result my URLs are just:

/%postname%/

And everything works like a charm.

If you expect a really large number of posts (thousands) on your website, though, having top-level categories may still be a good idea. For small sites, it's just a big waste in all sorts of ways.

Oh and as a result of removing the categories on my websites, it looks like I gained in rank since I get more traction. Not a lot more, but I still noticed.

Redirect—to answer your question

I don't know of a plugin to redirect from sub-paths to the main path. Such may exist. Of course, there are plugins you could use to create redirects by hand, but that would be really tedious.

Note that a large number of 301 is not ideal for a website. You'll notice that Google Console reports those as errors (although the new console version does not mark them as errors but warnings. So it may be fine as long as you add a single such 301.)

Canonicalization

Another way for Google is to fix the canonicalization of the page. So instead of a redirect, you create a canonical meta tag which includes the path you want, whatever the sub-categories. I'm not too sure how you control that under WordPress. I would suggest you test the various plugins that say they can create/fix your canonical path.

To verify the canonical, look at the resulting page source and make sure that the header meta tag looks correct. It has to be a full URL (i.e. including the protocol, domain name, and path.)

Note that Google still gives you a warning about such pages, saying that it found page blah with canonical foo. This is fine, though.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.