WooCommerce: Redirect Empty Paginated Category Pages (404)

Street scene featuring a bicycle detour sign and metal railings, guiding traffic.

In a recent Business Bloomer Club Slack thread, a WooCommerce developer faced a common but frustrating issue: their website was generating 404 errors for paginated product category URLs that no longer had enough products to justify multiple pages.

For example, /product-category/toys-gifts/page/3/ would show a 404 error if there weren’t enough products to fill that third page. This often happens when products are removed or recategorized, and while the base category URL remains valid, these deeper pagination URLs become orphaned.

The goal was to redirect those invalid paginated URLs back to the main category page to avoid broken links and improve user experience. What followed was a conversation about WooCommerce pagination, 404 behavior, and a working solution.

Understanding the Problem

WooCommerce uses paginated URLs to break up long product category archives. However, when products are removed or the total number decreases, pages like /page/3/ might no longer be valid. Unfortunately, these 404s are not automatically handled by WooCommerce, and traditional redirect logic using template_redirect doesn’t run on 404 pages—so a different approach is needed.

Why template_redirect Isn’t Enough

An initial attempt used the template_redirect hook:

add_action( 'template_redirect', 'bbloomer_redirect_paginated_category_to_main' );
function bbloomer_redirect_paginated_category_to_main() {
    if ( is_product_category() && is_paged() ) {
        wp_redirect( get_term_link( get_queried_object() ), 301 );
        exit;
    }
}

While this works for valid paginated category pages, it fails for 404s. That’s because WordPress never reaches template_redirect when handling 404 requests.

The Correct Solution

To fix this, the redirect logic needs to run even when the page results in a 404. The updated solution hooks into template_redirect and checks if the current request is a 404 and is a paginated category archive:

add_action( 'template_redirect', 'bbloomer_redirect_empty_category_pages' );

function bbloomer_redirect_empty_category_pages() {
	if ( is_404() && is_paged() && isset( $_GET['paged'] ) ) return;

	if ( is_404() && preg_match( '%product-category/.*/page/%', $_SERVER['REQUEST_URI'] ) ) {
		global $wp;
		$current_url = home_url( add_query_arg( array(), $wp->request ) );
		$parts = explode( '/page/', $current_url );
		if ( isset( $parts[0] ) ) {
			wp_redirect( $parts[0 ], 301 );
			exit;
		}
	}
}

This code checks the request URI, looks for the /page/ segment inside a product category path, and then redirects to the base category URL. It runs even for 404 responses and is safe to use as long as your URL structure follows WooCommerce defaults.

Conclusion

If you’re seeing 404s on paginated product category pages in WooCommerce, and you want to automatically redirect those to the main category page, you need a redirect that triggers even on 404 templates. The fix above handles exactly that, improving your user experience and preserving SEO value.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *