I have a set of redirects setup for some sections of my website which I want paginated. For example, for my notes section, /notes/?page=2
should redirect to the page /notes/page/2.html
.
Here’s one of the redirects I’ve added to my netlify.toml
file:
[[redirects]]
from = "/notes/"
to = "/notes/page/:p.html"
status = 200
force = true
[redirects.query]
page = ":p"
(When I say redirect, I mean rewrite – the URL should stay the same but a different HTML page should be fetched in the background.)
You can see an example here: https://paulrobertlloyd.com/notes/?page=4. This redirect will likely work the very first time you visit this page, or if you type in a pagination query manually, but will then revert to the broken state where only the first page is shown, regardless of the query string value given.
These redirects work locally when I use netlify dev
:
◈ Rewrote URL to /notes/page/2.html?page=2
There are no reported errors with redirects when the site is deployed:
1222 redirect rules processed
All redirect rules deployed without errors.
The redirects playground shows this redirect syntax to be correct:
Success!
from = "/notes/" to = "/notes/page/:p.html" status = 200 force = true [query] page = ":p"
Everything seems to be present and correct. And yet.
It seems as if there’s some weird caching behaviour occurring in production, but for the life of me I can’t figure out what it might be. I have a service worker running on my site, but disabling that makes no difference either.
Can anyone point me in the right direction and help me solve this mystery?