Can we use RM to apply a 301 for *any* Sub Category URL to its parent?

[ad_1]

RewriteRule ^shop/[^/]+/[^/]+/([^/]+)/?$ /shop/$1 [R=301,L]

We have a site where sometimes Google has indexed a page where it is linked like this:

/shop/mens/jeans/jean-product/

But we need it to already redirect to:

/shop/mens/jean-product/

The site is written in this way, but Google has oddly indexed longer versions with the “jeans” in the sub category.

The Rewrite above was given to me, but it doesn’t do anything at all.

Can someone please help?  Looking at it, surely it should have the various $1…$2 within it, but my knowledge is extremely rusty.

Can Rank Math be used to enter this, and set it up so it works for any ‘longer’ URL that has both Cat and Sub Cat?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer