serve
serve copied to clipboard
Make redirections support query strings
I've been using version 6.5.8 and I was able to serve URLs with query string, example: http://localhost:5000/code.html?26482
The query string "?26482"
is missing a parameter name, and that's intentional because it's the only way it works.
Adding the parameter causes it to serve without the query string, try: http://localhost:5000/code.html?id=26482 for instance.
When updated to version 7, none of this works (with parameter and without parameter).
Using @6.5.8
won't have this issue.
I checked the problem which version 8 has:
The request another.html?param=value
did reach the server, then a 301 (move permanently) got returned to another.html
with query params being stripped off.
@fab1o Hi, I checked the source code of serve-handler
, which is one of the dependencies of serve
. Turns out that url clean
feature is on by default, so xxx/xxx.html
will trigger a 301 redirect response with Location
header as xxx/xxx
(.html
stripped off). This process will also ignore any query param.
One quick fix for this is to create a serve.json
at the servering root directory:
{
"cleanUrls": false
}
That way will disable the redirection process. Other configure options might also work, but I haven't tried.
@leo And I don't know if redirecting without query params is really an issue, or is just a standard. But according to RFC 7231, the Location
header could be any valid URI?
Hi, I actually kind of need this feature like right now. Just in case you don't have time, I am happy to make a pull request to serve-handler
: )
@bidiu What is the status of this? With the official way of redirecting www to root domain (https://zeit.co/guides/redirect-from-www/) I have the issue that query params are not taken into account. It is removing the query params.
shameless self-promotion alert:
this feature is available in my @warren-bank/serve
fork of serve
see: usage for the optional boolean preserveQuery
and preserveHash
attributes in redirect rules
@warren-bank are you interested in merging some of these features back upstream? 🙏