Following up with more context. Hoping @fool or @Dennis can help me out.
So Iāve been playing with this a bit more to try and figure it out. Iāve found that doing a regular redirect rule works as expected. But using rewrites doesnāt work as I would expect.
Note: all of these examples are using my preview build at: https://5ff7956eba84190008348a88--macosicongallery.netlify.app
Redirects (301s)
Hereās the redirect rule in my _redirects
file:
/netlify-support-test-no-200 /404.html?foo=bar
Because I didnāt specify a HTTP code, it uses a 301 and redirects the user from one path to another with the specified query params.
If I curl that resource, I can see I get a 301 redirect to the 404 page with the query parameters.
If I hit that URL in my browser ā /netlify-support-test-no-200
ā it redirects to the 404 page with the query parameters in the URL bar.
Cool, that works just as expected.
Rewrites and proxies (200s)
If I setup a URL to rewrite with a 200, then I donāt see the query parameters show up. Hereās the rule in my _redirects
file:
/netlify-support-test /404.html?foo=bar 200
If I curl this resource, it returns a 200 with the contents of the 404 page. That makes sense:
If I hit it directly in my browser (/netlify-support-test
) I see the contents of the 404 page (same as the redirect above) but my browserās URL doesnāt change (and doesnāt have the query params in it)
That all makes sense. Because this is a rewrite, Netlify is making a request to the URL with the query params behind the scenes, so any query params are hidden from the URL bar and from the curl.
But that request thatās happening behind the scenes isnāt working as expected
I have one more rewrite rule setup. This one is designed to be a rewrite that points to a URL with query params. Hereās the rule:
/netlify-support-test-params /.netlify/functions/netlify-support-test?foo=bar 200
Note that this is pointing at a netlify (lambda) function with explicit query parameters. The lambda functionās code is really simple. Itās essentially echoing back the query parameters.
So my expectation is that if I curl /netlify-support-test-params
Iāll get a 200 and it will echo back {"query": {"foo": "bar"}
. But it does not. The lambda receives no query parameters:
However, if I do include some query params myself in the request, it echoes those back. For example, if I curl /netlify-support-test-params?hello=world
, I get a 200 with {"query":{"hello":"world"}}
echoed back to me:
What gives?
Is my expectation incorrect here? It appears Netlifyās rewrites/proxy engine is not actually making a request with query params in tow. To restate:
Given this rule: /path /rewrite?with=params 200
I expect: a request to /path
will result in Netlify making a request to /rewrite?with=params
behind the scenes and then returning a 200 result to /path
.
But what I get is that a request to /path
results in, apparently, Netlify making a request to /rewrite
without any query params and returning a 200 result to /path
.