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

Redirect partial URLs to WooCommerce Categories WordPress

  • SOLVED

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

I am using the [[LINK href="https://wordpress.org/plugins/redirection/"]]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.

E.g:

Any URL beginning with:

http://evatron.com/index-pag-product-cid-9[rest of URL here]

Needs to redirect to:

http://evatron.com/product-category/hand-held-enclosures-remote/


So, this URL would be redirected to the category:

http://evatron.com/index-pag-product-cid-9-sid-167-pid-1584-l-2.html


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

http://evatron.com/product-category/hand-held-enclosures-remote/-sid-167-pid-1584-l-2.html


Can anyone help with right regex to make this happen?

Answers (3)

2015-05-08

Reigel Gallarde answers:

have you tried

/index-pag-product-cid-9(.*)
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="http://printmydesigns.ml/index-pag-product-cid-9-sid-167-pid-1584-l-2.html"]]http://printmydesigns.ml/index-pag-product-cid-9-sid-167-pid-1584-l-2.html[[/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.

2015-05-08

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.

2015-05-08

Firoja_Imtosupport answers:

Hi,

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

Thanks


Firoja_Imtosupport comments:

Hi,

You can use plugin from https://wordpress.org/plugins/search-and-replace/


Firoja_Imtosupport comments:

Hi,
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:

Hi,

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 http://evatron.com/index-pag-product-cid-9[rest of URL here] in your browser and in index.php write below
echo $_SERVER['REQUEST_URI'];
exit;


Sam Cranwell comments:

I think you are misunderstanding my request.

http://evatron.com/index-pag-product-cid-9..... 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:

Hi,

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