Redirect and retain query string


#1

Hi, I am using Fastly to redirect a number of urls from one domain to another using the instructions here: https://docs.fastly.com/guides/performance-tuning/generating-http-redirects-at-the-edge

This is great except that I lose any querystring parameters which were in the original request. Is there any way that I can configure my redirects so that they retain the original querystring?

Thanks
Rupert


#2

Hi Rupert,

I’ve whipped up a quick fiddle example of req.url being used in a response after the host that “brings through” the URL and query string parameter here: https://fiddle.fastlydemo.net/fiddle/f538c265

Essentially you want the source field to say something like:
"http://www.example.com" + req.url
(The + sign is optional)

If you want to modify the URL and state that in the location header and only bring the qs through there is req.url.qs. Feel free to clone my fiddle example and experiment.


#3

Richard, you are a legend thank you!

Also I was completely unaware of the fiddle tool, that is super useful.