How can redirect old link to new link after user edited

I want to build a blog by next and strapi like dev.to.But i have a problem with slug not have an idea to fix it.
With each article, I will create the path with the syntax: https://domain.com/username/slug (it like dev.to).
Example of dev.to: Easy user authentication with Next.js - DEV Community
But a problem , when the user change username, the path will be changed together, this time new url will be:

  • Old: https:// domain[.]com/username/slug
  • New: https:// domain[.]com/new_username/slug

So I want if users visit the old URL it be auto-redirect to the new url.
How can do it? how can a designer database in this case?
I no experience about this.I hope will be a little bit suggest from everybody. Thanks!

did you got any solution?

Yes, I find a solution…i will add url every time request to get a article.
I will be set article.url = domain+article.user.username+article.slug to response…it will always be update

Thanks trangchongcheng !

1 Like

Hi @trangchongcheng, I’m fresher in strapi, can you please explain in detail? It’s really appreciated.

I guess the solution would be to also add article id to url and then when loading the page only load article by id and ignore the slug, such as https://domain.com/123/some-slug-that-can-change

I would prefer to just have https://domain.com/some-slug but I don’t have a good idea how to implement redirects in case slug changes.