menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Trying to pass query parameters along with a trailing slash redirect

July 31, 2019 at 4:02pm

Trying to pass query parameters along with a trailing slash redirect

July 31, 2019 at 4:02pm

For every route in now.json I have redirect for the trailing slash back to the normal route.

{
"src": "/(?<city>[^/]+)/subscribe/",
"status": 301,
"headers": {
"Location": "/$city/subscribe"
}
},

I want to pass along any query parameters with the redirect so /city/subscribe/?test=test would redirect to /city/subscribe?test=test.

{
"src": "/(?<city>[^/]+)/subscribe/(?<xquery>\\?[^/]+|$)",
"status": 301,
"headers": {
"Location": "/$city/subscribe$xquery"
}
},

I think that should work but it seems to always leave off the query string. I'm not sure if I'm not escaping the ? correctly or if something else is going on because I think the regex is right. https://regex101.com/r/7hBT5n/5


July 31, 2019 at 6:12pm

The querystring is not taken into consideration by "dest". I will check if we have a reserved word for it, one moment.

  • reply
  • like

We don't support this with now.json yet. However, you can do this with a little node function in the meantime. I relayed this to the team!

Edited
  • reply
  • like

Hey Nick, the query strings should be passed on anyways, without you having to do anything. Please let me know if that doesn't work, we'll then look into it and make sure you'll arrive at a situation where it works perfectly.

  • reply
  • like

This 👆is only for "src" and "dest", however. We're working on a solution that allows for setting redirects using a specific "redirects" configuration property, but at the moment this has to be handled using a serverless function.

  • reply
  • like

August 1, 2019 at 2:08pm

I see

I have a few other redirect node functions. Adding one here shouldn't be a problem.

  • reply
  • like

On a redirect it doesn't seem to pass the query string along. It just goes directly to the "Location" path. Which is what I would expect without adding the query string onto the redirect Location, but adding that doesn't seem to work either.

  • reply
  • like

Indeed. As of today, this is not yet possible using config, you'd have to use a serverless function that does the redirection. In the future, we'll be providing a "redirects" config property that makes this much easier.

like-fill
1
  • reply
  • like

Sorry about that I didn't see your second message before I replied. Thanks!

  • reply
  • like

August 30, 2019 at 10:34am

Hello guys,

is “redirects” config scheduled or it is just far future enhacement?

  • reply
  • like

It will definitely happen before the end of the year. Most likely within September.

  • reply
  • like

October 15, 2019 at 8:24am

any news about this feature?

  • reply
  • like

February 27, 2020 at 7:53am

I'm also interested in this one. I have same issue, mostly because of Google Ads. If a google ads url has query string with /?test=test redirect is going to happen and query string will be removed. If we change trailingSlash option to true, then url without slash ?test=test is also redirecting and removing query string from it.

Edited
  • reply
  • like
private
This channel has been archived