Here’s a WooCommerce quirk that flies under the radar until your site audit flags it: every subcategory on your store is accessible under two different URLs simultaneously.
For example, a subcategory “Footblall balls” nested under “Balls” will be reachable at both:
- /product-category/football-balls/
- /product-category/balls/football-balls/
Both URLs load the exact same page. WooCommerce sets a canonical tag pointing to the full hierarchical URL, but that’s not enough Google and especially Bing will still crawl both, split your link equity, and may index the wrong one.
Why Canonical Tags Alone Aren’t Enough
In theory, a canonical tag should tell search engines which URL is the “real” one. In practice, Google has been increasingly ignoring canonical hints and making its own indexing decisions. Bing is even less reliable about respecting them. If both URLs are accessible and return a 200 status, crawlers will visit both wasting crawl budget and diluting your page authority.
The only bulletproof solution is a 301 redirect from the short URL to the canonical full URL.
The Fix
Add this snippet to your functions.php (child theme) or via Code Snippets plugin:
add_action( 'template_redirect', function() {
if ( is_product_category() ) {
$term = get_queried_object();
if ( $term && $term->parent ) {
if ( get_query_var( 'paged' ) > 1 ) {
return;
}
$canonical = get_term_link( $term );
$current = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_clean = strtok( $current, '?' );
if ( trailingslashit( $current_clean ) !== trailingslashit( $canonical ) ) {
wp_redirect( $canonical, 301 );
exit;
}
}
}
});
How It Works
The snippet fires on every product category page and checks two things. First, does the current category have a parent ($term->parent)? If not it’s a top-level category and nothing happens. Second, does the current URL match the canonical URL WooCommerce expects? If they don’t match, it issues a 301 redirect to the correct full URL. Query strings are preserved so paginated URLs like ?page=2 or /page/2/ won’t break.
What to Update After Adding the Snippet
The redirect will silently fix any incoming links or direct URL visits, but you should also manually update internal links that point to the short URLs:
- Main navigation menu
- Footer menu
- Any category links in hero blocks or homepage sections
This avoids unnecessary redirect hops for your own visitors and keeps your internal linking clean.
Result
Each subcategory will have exactly one accessible URL. Crawl budget stops being wasted on duplicates, link equity consolidates on the canonical page, and your site audit stops flagging duplicate content warnings. As always, clear your cache after adding the snippet.
Anton aka oswoptimize.


Leave a Reply