# Redirect CakePHP 2 urls to 4

**URL:** <https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213>\
**Category:** Uncategorized\
**Created:** [February 1, 2020, 10:32pm UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213 "2020-02-01T22:32:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3420_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [February 1, 2020, 10:32pm UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/1 "2020-02-01T22:32:30Z")

</div>

Hello upgrading time, from 2 to 4 😉

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](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.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 1, 2020, 11:08pm UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/2 "2020-02-01T23:08:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3420_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [February 10, 2020, 8:50am UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/3 "2020-02-10T08:50:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 10, 2020, 3:19pm UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/4 "2020-02-10T15:19:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3420_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [February 11, 2020, 8:37am UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/5 "2020-02-11T08:37:14Z")

</div>

Hallo, thanks for your help

---

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3420_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [November 5, 2026, 2:15pm UTC](https://discourse.cakephp.org/t/redirect-cakephp-2-urls-to-4/7213/6 "2026-11-05T14:15:23Z")

</div>

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.
