Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Redirect partial URLs to WooCommerce Categories WordPress


I am trying to redirect traffic from URLs on an old site to a new.

I am using the [[LINK href=""]]Redirection[[/LINK]] plugin which works well.

However, on the old website there are 1000s of pages that need redirecting so rather than do each one individually I would like to redirect them to their parent category on the new site based on information within the URL.


Any URL beginning with:[rest of URL here]

Needs to redirect to:

So, this URL would be redirected to the category:

The redirection plugin supports regex but my attempts with it so far keep returning a mash up of the two URLs like this:

Can anyone help with right regex to make this happen?

Answers (3)


Reigel Gallarde answers:

have you tried

as your Source URL?
and Regular expression is checked.

I've attached an image that demonstrate my setup...

you can visit this link to test..

[[LINK href=""]][[/LINK]]

Sam Cranwell comments:

Winner! Perfect thank you.

I had been using ^/index-pag-product-cid-9.*

Now I can set all my redirects up.


Shoeb mirza answers:

Downloading Database and editing your URL by replacing it with your desired url and then re-uploading will do the job within few minutes...

Sam Cranwell comments:

This wont work for us. We wish to retain the URL structure of the new website and not replicate the old.


Firoja_Imtosupport answers:


Please use Search and Replace plugin, This plugin will do your task in some minutes.


Firoja_Imtosupport comments:


You can use plugin from

Firoja_Imtosupport comments:

can you write echo $_SERVER['REQUEST_URI'] on your index.php and share what u get with me?

Sam Cranwell comments:

The URLs I am looking to redirect are not in my database. They are URLs from an older version of the website made up of static html pages.

I need to set 301 redirects from these URLs so we don't lose any search engine traffic while the site being re-indexed by Google.

So unfortunately editing the database wont do it.

Firoja_Imtosupport comments:


We can write an redirect in your index file , so please echo $_SERVER['REQUEST_URI'] and let me know so we can add redirect condition.

Firoja_Imtosupport comments:

i mean to say type[rest of URL here] in your browser and in index.php write below

Sam Cranwell comments:

I think you are misunderstanding my request. are URLs from the old version of the website. These pages are now offline. The 301 redirects are to tell search engines they have been moved permanently.

I am after a regex pattern I can place in our Redirection plugin that will direct partial URLs to specific product categories.

Firoja_Imtosupport comments:


My appologise for not understanding your request properly, i will search for pattern and update you