Hi. I’ve implemented a feature to redirect all external links on my website by passing them a netlify function. With netlify dev
, everything works fine. When I open http://localhost:8888/redirect?to=https://www.instagram.com/netlify, I end up on Netlify (@netlify) • Instagram photos and videos.
But when I deploy the site (cannot give the URL here), opening http://deployed-website.com/redirect?to=https://www.instagram.com/netlify, brings me to Netlify (@netlify) • Instagram photos and videos. I don’t understand why I got the to
query here and only on deployed site.
Here is a part of my function code:
// `to` is required by redirect rule in netlify.toml file
const param_to = event.queryStringParameters?.to
const decodedURI = decodeURIComponent(param_to)
const source = decodedURI !== param_to ? decodedURI : param_to
// ...
return {
statusCode: 302,
headers: {
"Location": decodedURI
}
}
Thanks for help.