Redirect CakePHP 2 urls to 4

Hello upgrading time, from 2 to 4 :wink:

But I have question about redirection form old url to new format.

Example:

CakePHP 2:

Router::connect('/satovi/:id-:slug/*', array('controller'=>'watches','action'=>'view','id' => '[0-9]+'),array('pass' => array('id','slug'),'id' => '[0-9]+'));

This generate link like:

https://detas.ba/satovi/7555-Tissot_T101_917_11_116_00

Now we are in upgrading process, and we want all old incoming get request redirect to new url format.

example: …/satovi/tissot/t101-917… etc

Please recommend the most painless solution, from the SEO point of view.

Do you want the URLs to all change, or are you just thinking that they have to? Because it seems like it should be possible to keep them the same, if you want to.

Yes, I want to redirect old URLs to new ones with code 302. Best place for such actions is middleware or router? Thanks.

The lowest server overhead place to do redirection is in .htaccess. Should be quite possible with regex matching.

1 Like

Hallo, thanks for your help

I just came across this old thread while Googling, so I thought I’d share how we solved it.

We kept a legacy route to catch old URLs and extract the original product ID. Using that ID, the application finds the product in the database, generates its new canonical URL, and returns a permanent 301 redirect.

This is more reliable than using regex in .htaccess, especially when product names, categories, or slugs have changed.

Old URLs and backlinks still work, with visitors and search engines redirected directly to the new URL.