Support Forums

How to add a query parameter to redirect when other query parameters already exist

I am putting this here to hopefully save others hours of time for something not well documented - perhaps Netlify could expand their documentation around query parameters for this common use case.

In redirect in a netlify.toml file I needed to add a “key” query parameter to query parameters that sent from the code for this particular google api (q, source, target). Through trial and error I have found a way:

command = '''
    sed -i "s|Google_Translate_Placeholder|$Google_Translate_API_Key|g" netlify.toml && \
    npm run build'''

force = true
from = "/translate/"
query = {q = ":q", source = ":source", target = ":target"}
status = 200
to = "https://translation.googleapis.com/language/translate/v2/?q=:q&source=:source&target=:target&key=Google_Translate_Placeholder"

The key was to respecify the query line items in the “to” line, along with the new one.

Hi @rwoodnz,

Thank you for sharing.