Next13 App router: Redirect to new url with new dynamic slug string
Unanswered
Himalayan posted this in #help-forum
HimalayanOP
I have structure like this "products/[topic]/[slug]"
How can i redirect from path : products/tools/12 ----> products/work/hammer
i changed url with new readable slug naming and old links now return 404 but i need permanent redirect to new url with readable url
p.s i can't just get new slug string from old links^ so i have to make request for new slug params to server
How can i redirect from path : products/tools/12 ----> products/work/hammer
i changed url with new readable slug naming and old links now return 404 but i need permanent redirect to new url with readable url
p.s i can't just get new slug string from old links^ so i have to make request for new slug params to server
12 Replies
Thrianta
I believe you do it simply using redirect(“/products/work/hammerâ€) when ur params match “tools†and 12
HimalayanOP
how i should redirect user that comes from external resourse just cliking link with old path
and i have more than 1000+ dynamic slugs
Thrianta
what do you mean as an external resource?
When a request is sent to your server side route it’ll return a temporary redirect if you use the redirect function
You can have a switch-case detecting those which would make it easier to control those slugs
what’s the reasoning behind the redirection from /tools/12 to /work/hammer
HimalayanOP
@Thrianta ru?
HimalayanOP
в общем проблема в оптимизации Ñео Ñтраницы так как раньше Ñтраница отдавала урлы по конкретному товару через айди но ÑÐµÐ¹Ñ‡Ð°Ñ Ñто изменилоÑÑŒ на читаемые тайтлы, ÑоответÑтвенно вÑе Ñтарые ÑÑылки протухли и теперь никуда не ведут, логично что хотелоÑÑŒ бы перенаправлÑÑ‚ÑŒ Ð¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ñ‚ÐµÐ»Ñ Ð½Ð° новые актуальные Ñтраницы а так как Ñтраниц много вручную каждую не пропиÑать ÑоотвеÑтвенно нужен метод Ð¾Ð¿Ñ€ÐµÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ñтарого пути и редиректа на актуальный
Thrianta
ну тогда до Ñих пор можно иÑпользовать то что Ñ Ð¿Ð¾Ð¿Ñ‹Ñ‚Ð°Ð»ÑÑ Ð¾Ð¿Ð¸Ñать 🥶
you can make some sort of middleware which would match those urls to the new ones
like combine them together with a “_†and then get a redirect value from a hashmap of redirects