I’m having a hard time understanding why rewrites are working in a way that’s not matching my expectations.
I’m running a netlify dev server which is mimicking the rewrites functionality.
I have a URL with key/value parameters and I want to serve some static HTML pages I generate based on what the query parameters are.
For example, when I have a key and a value in the URL:
And when I have only the key present in the URL, I want to serve the “index” page for that:
I have a redirects file that looks like this:
# For key + value pairs /search color=:value /search/_color/:value.html 200 /search category=:value /search/_category/:value.html 200 # For keys _only_ /search color /search/_color/index.html 200 /search category /search/_category/index.html 200
This works almost as expected. But when I try
/search?category rather than serving me the
_category/index.html file, it serves the
I assume that has something to do with the fact that A) the parameter is empty/missing and B) it finds the color rule first in my redirects file?
What am I missing here? Is it wrong to assume that the mere presence of a matched query parameter should match to specific route? i.e. given this:
/path foo /foo.html 200 /path bar /bar.html 200
You would think
/path?foo would serve you
/path?bar would serve you
bar.html, but that doesn’t happen. In both cases
foo.html is served. Why is that?
Is there a way to set this up such that it would go specific to generic in terms of what rewrite rules exist in the redirects file, eventually falling back to a generic
index.html file, like this: