NodeJS Routes domainA to domainB with parameter retention

NodeJS, Mac, Wappler 6.8

Does anyone know how to take a url like this
https://www.example.com/blog/wp-content/uploads/2018/12/DSC_2094-495x400.jpg
and redirect it to
https://blog.example.com/wp-content/uploads/2018/12/DSC_2094-495x400.jpg

Basically i have moved my blog from domain with parameter blog
https://www.example.com/blog
to now a blog subdomain
https://blog.example.com/

{
      "path": "/blog/*",
      "url": "",
      "name": "BlogMoved",
      "routeType": "redirect",
      "redirect": "https://blog.example.com/"
}

This works but drops all the parameters that were previously in the clicked url, which makes perfect sense, but what do i change to retain the parameters of the original link only dropping the first part /blog

Convert that route to a server action

$_SERVER, Condition and redirect step are what you need

Hope you can figure it out, don't have time to explain now

1 Like

Amazing, thank you @Apple so nice and easy.

If you want to get this done faster (in terms of server response), you can also configure a custom middleware.

Should be easy to configure. Ask AI for sample code.

2 Likes

Thanks Sid, great tip, reading through it now.