How to always direct to primary/canonical URL with posts in multiple categories
-
Hello,
I hope I’m in the right place for this. I have searched around for this exact question and while I’ve found tangential discussions, none were looking for this exact behavior. Apologies if I have missed any!
BACKGROUND
I set up my website years ago with the permalink structure:/%category%/%postname%/
but didn’t realize that it’s not ideal to do so when you have posts assigned to multiple categories. This results in posts being available at multiple URLs (default behavior for this setup from my understanding).
My concern is not with selecting a primary/canonical URL as I have Yoast handling this. My issue is that because you can access a post at multiple URLs, this causes problems with page caching/purging, and Google Analytics given they are treated as “separate” posts.
So, for example if you were to visit:
mydomain.org/category1/post-slug
mydomain.org/category2/post-slugThe URL in the address bar will stay the same as what you visited. Even if category1 is the primary/canonical, if you visit with /category2/ it will remain that in the address bar. Again this is standard behavior, from what I understand. However, this leads to that post being cached separately within page caching and then not purge/update properly. It also means Google Analytics logs it as a different post.
DESIRED BEHAVIOR (IF POSSIBLE?)
I’m hoping to find a way to have WordPress redirect/defer (maybe not correct terms) to the primary/canonical whenever you try to visit another assigned category.This already happens if you replace the category with a category on my website that the post is not in. So, for example, let’s say for the example above, the post is in “category1” and “category2” but not “category3”.
In that case, if you visit
mydomain.org/category3/post-slugYou are brought to the primary/canonical at:
mydomain.org/category1/post-slugIs there a way to achieve this even with non-primary/non-canonical assigned categories? That way no one ever ends up on the non-canonical/non-primary.
_____________________
POSSIBLE ALTERNATIVES??
1. I have considered going through and assigning only a single category to my posts, however I use categories for my site’s “browse” navigation and archives and most posts legitimately belong in multiple categories for that functionality.2. Another thought was to change my permalinks to not have categories, but from what I’ve read this is strongly not advised from an SEO standpoint (and for existing links around the web)
3. A third option that’s seems messy was to create a custom “category substitute” taxonomy that I’d use purely for my “browse” page for user filtering. That way I could assign posts to multiple “category substitutes” for the filtering, but only assign one “true” WordPress category for the permalink. The issue with this, though, is that the posts that are assigned to multiple categories would no longer be on those category archives. (And this may be a horrible idea!)
_____________________
I hope I’ve made sense. If I can further clarify, please let me know. I would greatly appreciate any input!
Thank you so very much
- The topic ‘How to always direct to primary/canonical URL with posts in multiple categories’ is closed to new replies.