WPEC Products in multiple categories cause SEO duplicates

Overview

Whilst trying to customise a bought in template and digging around in a customer's WordPress eCommerce system, it occurred to me that there is a fundamental design flaw in the system from two perspectives.  Both have to do with the way that Products are assigned to Categories and how you navigate from a Category to a Product.

Permanent Categories

If my understanding is right, which it could easily not be, then when you assign a Product to a Category this must be a permanent assignment. Why - If you ever remove it, you may end up with an orphaned URL which Google and the rest of the world might have book-marked.

For example; say we are a book store and have divided our store into three basic categories; fiction, non-fiction and General Interest.

We receive a new book eg: ("Zen and the Art of Motorcycle Maintenance") and decide to assign it to the non-fiction category.  Depending how we have setup our Permalinks we might end up with a URL to this book as http://www.ourbookstore.com/non-fiction/Zen-and-the-Art-of-Motorcycle-Maintenance

However, the next day we decide that we shouldn't have put it in non-fiction but general interest.  We therefore go into WPEC and change the category assignment from non-fiction to general-interest.  Great!  It all works and now we can see the book at http://www.ourbookstore.com/general-interest/Zen-and-the-Art-of-Motorcycle-Maintenance

The day after that, we are browsing through our server logs (as we all do) and notice that someone is still trying to access the old URL of http://www.ourbookstore.com/non-fiction/Zen-and-the-Art-of-Motorcycle-Maintenance.   Further  investigation shows that during the first night Google spidered our site and caught the non-fiction URL and has not corrected it.

SEO and duplicate content

The second reason this is a fundamental flaw is from an SEO perspective.  If I assign a product to more than one category (eg: non-fiction and general-interest) then this book will have two URLs.  Whereas, you might think that is no bad thing, in fact, maybe even a good thing, Google won't like it.  It is one of Google's objectives to cut down on duplication on the internet.  It is even believed that they may penalise a site that is consistently producing duplicate content.

If you have hundreds or even thousands of products and each product is in 2 or more categories, then you could be penalised by Google.  Maybe you already have been!

Solution

Ideally, WPEC shouldn't reference the product as part of the category.  The book should always be stored at, for example, http://www.ourbookstore.com/books/Zen-and-the-Art-of-Motorcycle-Maintenance.  In this way, if you move the product from A to B, the product URL itself doesn't move.

Well, I'm not a WordPress guru.  I can find my way around OK but navigating the multiple layers of WPEC as well ...

In the meantime, it dawned on me the other evening whilst walking the dogs, that we could easily correct this URL by using a technique called "URL rewriting". By setting up some simple rules we could re-write the offending URLs so that it always appeared as if the product had a permanent URL independent of category.

Step 1; we need to setup a catch all Category.  In this case, as in my example just above, I'm going to call it books.  Now, every product I add to the system, I assign to the category books as well as to fiction, non-fiction or general-interest.  So, if I navigated to http://www.ourbookstore.com/books/ I would see every book in the store.

Step 2; we define a rule to redirect any category/product URL which isn't  books/book-title to books/book-title.

How do we setup a rule, you may well ask.  The answer is, it depends on your experience and the size of your store.  If you are not a nerdy type and you maintain your own WPEC store, then you can use a "redirect" plugin (like this one http://urbangiraffe.com/plugins/redirection/) or if you are a serious techy you can use htaccess.

So the logic of the rule is

1. If the URL does not contain my "catch all" category (eg: "books") then

2. and the URL contains a category followed by something else then

3. re-write the URL to my new catch-all category (books) plus whatever followed that part of the URL

Lets have a look at some examples;

/non-fiction/zen-and-the-art -> /books/zen-and-the-art

/non-fiction/zen-and-the-art/search=some-text -> /books/zen-and-the-art/search=some-text

/non-fiction -> doesn't get re-written as there is nothing after the category name

/something-else -> doesn't get re-written because it isn't a category

To make this easier, WPEC preceeds all its' URLs with a /p/ showing that this is a URL to a product or category/product

Therefore we can use this "/p/" to distinguish WPEC urls from other wordpress urls.

With htaccess we can achieve all of this with just 2 lines of code as follows:


RewriteCond %{REQUEST_URI} ^(?!/p/books).*$
# this RewriteCond is needed to stop a rewrite loop
# In other words, ignore any URL which already contains /p/books
RewriteRule ^p/(.+?)/(.*)$ /p/books/$2 [R=301,L]

On further testing, I found that there was a huge limitation in this approach.

Whereas, it will work perfectly if you have a flat category structure, as soon as you have nested categories, you can never tell whether the last branch of the URL is a product title or a category title and therefore you cannot write a rule for it ...

I did finally find a way of hacking the core WPSC product permalink function to do this and now I have my products all pointing to http://www.mystore.com/p/product-permalink ... you can find a short post about it here, but you will need to be happy editing core wordpress files to do this. If not, you can always ask me to do it for a small charge

Happy categorising!


Did you know you can hire me?

I take on projects of all sizes. From Consulting to large Development Projects.

If you're starting a new Yii project and would like some help to get setup and running or you need some help with a particular module or you just need someone to develop the whole dang thing, then just ask ...


Jumpstart Yii2 ... Coming Soon!

I'm in the process of planning a new course on Yii2 and want your feedback.

What is your preferred format? What did you think of my Yii 1.x video course "Beginning Yii"?

What would you like to see different?

How much would you pay?

Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com