Hi, thanks for the great free product. I have read this piece of documentation and can see the examples written in shell format, but would like to understand how to write the following in netlify.toml format:
The following match redirects a URL like: /store?id=my-blog-post to /blog/my-blog-post with a 301 redirect. This affects request URLs with an id query parameter only.
/store id=:id /blog/:id 301
I thought it might be this:
[[redirects]]
from = "/blackpool-hotels-with-parking/blackpool-(beach)?id= tgblk239"
to = "/blackpool-hotels-with-parking/blackpool-(beach)-:id"
query = {id = ":id"}
status = 301
…as the new url is: /blackpool-hotels-with-parking/blackpool-(beach)-tgblk239, but the toml rule I wrote results in this url: /blackpool-hotels-with-parking/blackpool-(beach)-?id=tgblk239
Also, if possible could you include code examples in both flavours?
Hey @hrishikesh thanks for getting back to me. OK, I have 30 pages that have a similar url structure, so is there a way to match them all with 1 rule, I was thinking this could work:
[[redirects]]
from = "/blackpool-hotels-with-parking/*?id=:id"
to = "/blackpool-hotels-with-parking/:splat-:id"
status = 301
query = {id = ":id"}
This probably would not work because with * matches everything as it is and it ignores the string after *. So, it will also ignore the ?id parameter.
You can instead use placeholders:
[[redirects]]
# one of the following should work
from = "/blackpool-hotels-with-parking/:path?id=:id"
#from = "/blackpool-hotels-with-parking/:path/?id=:id"
to = "/blackpool-hotels-with-parking/:path-:id"
status = 301
query = {id = ":id"}
[[redirects]]
from = "/blackpool-hotels-with-parking/boulevard-hotel-blackpool?id=:id"
to = "/blackpool-hotels-with-parking/boulevard-hotel-blackpool-:id"
status = 301
query = {id = ":id"}
I also re-deployed and added force = true, but it had no effect.
One big takeaway here is that placeholders will only work between two paths, i.e. /:placeholder/, and not as just a part of the path (with the exception being the last path, where you can append a query string param.
With this in mind, is there a nomenclature which will work for you?
Sorry @morganfeeney, I think I misunderstood the original request!
[[redirects]]
from = "/blackpool-hotels-with-parking/blackpool-(beach)"
to = "/blackpool-hotels-with-parking/blackpool-(beach)-:id"
status = 301
query = {id = ":id"}
That will redirect /blackpool-hotels-with-parking/blackpool-(beach)?id=demo to /blackpool-hotels-with-parking/blackpool-(beach)-demo?id=demo.
If you don’t want ?id=demo in the new (‘to’) path, you can update your rule with a alternate, dummy query string parameter… which actually comes in handy, for knowing if somebody followed the redirect or browsed directly to the new (‘to’) path.
to = "/blackpool-hotels-with-parking/blackpool-(beach)-:id?redir"