Netlify.toml redirects not working

After deploy I can’t seem to verify my redirects written with a netlify.toml file.

I have this from the deploy summary:

4 redirect rules processed
All redirect rules deployed without errors.

Yet a quick check visiting a redirected url does not result in a 301, but a 200

E.g.
[[redirects]]
from = “/?url=bybarner.dk&id=1184”
to = “/booking”
status = 301

This is how I copy the toml file:
nuxt generate && cp netlify.toml dist

Hey, it looks like youre trying to redirect through query parameters. While the query parameters should now be passed through automatically, I think you’d need to specify them. Winging it here but maybe something like this:

[[redirects]]
from = “/”
to = “/booking”
status = 301
query = {url = "bybarner.dk", id = "1184"}

The reason i’ve changed from to “/” is because I think you need this redirect to be applied at that route but only when the specified paramters are applied? If you need it to react to more dynamic url,id values you can use :url :id. (I hope)

Ill link a recent query parameter changer here: Changes to Redirects with query string parameters are coming that could be a good read.

and a link to the docs here: Redirect options | Netlify Docs

Shoot, didn’t see your reply, sorry for the delay mate.

I had actually read the docs numerous times concerning that part and ignored it due to the mentions of mapping the query parts.

Fault at from my side, however after restructuring and using your solution as a base it seems like its still failing to redirect.

Håndværk i top kvalitet should redirect to Håndværk i top kvalitet

this is my complete toml

[[redirects]]
  from = "/"
  to = "/"
  status = 301
  query = {url = "bybarner.dk", id = "1183"}

[[redirects]]
  from = "/"
  to = "/booking"
  status = 301
  query = {url = "bybarner.dk", id = "1184"}

[[redirects]]
  from = "/"
  to = "/behandlinger"
  status = 301
  query = {url = "bybarner.dk", id = "1185"}

[[redirects]]
  from = "/"
  to = "/om-os"
  status = 301
  query = {url = "bybarner.dk", id = "1186"}

Hmm, I’m Sorry for miss informing you! However, I think the query string specification is only to define what parameters to pass through, not the specific slug values.

It seems as though you can only pass on the values. IE:
from = “/”
to = /example/:id
id = :id

@Dennis I’ve tagged Dennis here just for confirmation that this hasn’t changed, as I’ve read a few replies from him on the topic now.

You could probably implement your own formatting to redirect as you need though.

No worries, it was a suggestion which I thought would work as well :slight_smile:

Without a doubt I’m a newbie at this, but my issue at hand is that I can’t quite figure out how to handle a fully queried path to a completely different path.
I’ll wait and see what Dennis replies - in the meantime I’ll try doing a _redirect file instead.

Hey, I notice it’s been some time now. Have you managed to find a solution? :slight_smile:
I’ll tag another staff member @Scott to see if we can get a more official response.

TLDR pie: Looking to redirect based on query slug values

Hey! Thanks for the ping @AaronP and thank you @Rnhj for your patience :slight_smile:!

Håndværk i top kvalitet should redirect to Håndværk i top kvalitet

The syntax for this, in a _redirects file, would look as follows:

/ url=bybarner.dk id=1184 /booking 301!

A few things to consider:

  • Because there is a page at Håndværk i top kvalitet (i.e. it responds with a 200 and not a 404) you’ll want to shadow your rule (301!)
  • Recent changes to how query string parameters are handled will mean that the query string parameters are automatically passed through to the new URL. Therefore, your users will actually end up at /booking?url=bybarner.dk&?id=1184. If you don’t want this to happen, you can follow the steps under Query String Parameters in this guide to append a ‘dummy’ parameter. Therefore, your rule would look something like:

/ url=bybarner.dk id=1184 /booking?no-query-string 301!

You could replace no-query-string with anything you like: redir might look cleaner, for example.

1 Like

Great solution, for my own edification is there a way to do this in a toml file as I tend to find it cleaner. Interesting that there’s a difference in functionality here.

Thank you for a clearcut answer. I did believe I had tried that solution, but I’ll give it a spin tonight and return with the result.

In the meantime I “second” @AaronP concerning the “toml way” of this feature.

Absolutely no difference, they’re parsed and ‘read’ the same in our backend, FWIW :slight_smile:

[[redirects]]
  from = "/"
  to = "/booking"
  status = 301
  force = true
  query = {url = "bybarner.dk",id = "1184"}
  conditions = {Language = ["en"], Country = ["US"], Role = ["admin"]}
2 Likes

Hmm, interesting, I tried these exact params, maybe it was because I didn’t use a force flag? It didn’t seem to pass the values through

@Scott I tried your approach last night and it works like a charm. force = true was the key to solving my issue. Thank you for your help and your’s as well @AaronP

1 Like

Niceeee, happy to hear! It was an oversight since the page already existed, we needed to force it.

Thanks Pie!

1 Like

Nice one!

Yeah, it needs the force because the index page exists, regardless of the fact that we’re passing query string parameters through :grinning_face_with_smiling_eyes:.

1 Like

It does make sense. The prior attempt I had was based on value placeholders instead of static values - that meant I didn’t want to force the redirect since it was only current with a specific set of values. :upside_down_face:

That being said, it could be nice doing a redirect where the piping of query params could be block completely since /?no-query is a bit hacky :wink:

1 Like