When managing a WooCommerce store, it’s common to rearrange products or remove them from certain categories. However, this can lead to an unexpected issue: paginated product category URLs (e.g., /product-category/shirts/page/3/
) may still be accessible even when that specific page no longer contains any products.
Instead of displaying a 404 error, it’s often better to redirect users back to the main category page to avoid confusion and improve user experience.
This is especially important for SEO, as you don’t want search engines indexing irrelevant or broken pages. The solution is to detect when a paginated product category archive is empty or invalid and redirect to the base category URL instead.
Below is a simple snippet you can add to your theme’s functions.php
or a custom plugin. It handles the redirect only when necessary, ensuring users and bots land on meaningful content.

PHP Snippet: Redirect Empty, Paginated, Category Pages to Main WooCommerce Product Category Page
This snippet hooks into the template_redirect
action to catch 404 pages that resemble paginated product category URLs.
It first retrieves the WooCommerce product category base slug from the permalink settings, making it compatible with custom or translated slugs.
Then, it checks if the current request matches the pattern of a paginated category page. If so, it extracts the category slug from the URL, confirms the category exists, and safely redirects the user to the main category page.
This prevents visitors and search engines from encountering empty or broken paginated URLs after products have been removed from that category.
/**
* @snippet Redirect Empty Paginated WooCommerce Category Pages
* @tutorial https://businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_action( 'template_redirect', 'bbloomer_redirect_empty_product_cat_pagination' );
function bbloomer_redirect_empty_product_cat_pagination() {
if ( is_404() ) {
$requested_url = $_SERVER['REQUEST_URI'];
$permalinks = wc_get_permalink_structure();
if ( preg_match( '#^/' . $permalinks['category_rewrite_slug'] . '/[^/]+/page/\d+/?#', $requested_url ) ) {
preg_match( '#/' . $permalinks['category_rewrite_slug'] . '/([^/]+)/#', $requested_url, $matches );
if ( isset( $matches[1] ) ) {
$term = get_term_by( 'slug', $matches[1], 'product_cat' );
if ( $term && ! is_wp_error( $term ) ) {
wp_safe_redirect( get_term_link( $term ) );
exit;
}
}
}
}
}
Hi, thanks for the snippet. Just wondering—would it be better to use a 301 redirect instead of 302 for SEO? Also, could this cause soft 404 issues if paginated category URLs were already indexed?
Should we also set canonical URLs to the base category to avoid duplication?
Hello there!
– 301 is better if you plan to NEVER use the paginated category page again, 302 is better if it’s temporary
– the 404 issue is exactly why we’re redirecting, so we avoid sending people from indexed URLs to 404
– honestly, I’m not an SEO so I can’t answer the last question, I’d say Woo should already do that out of the box if I were Woo