serve icon indicating copy to clipboard operation
serve copied to clipboard

Make redirections support query strings

Open fab1o opened this issue 6 years ago • 6 comments

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).

fab1o avatar May 30 '18 20:05 fab1o

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.

bidiu avatar Jun 09 '18 01:06 bidiu

@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?

bidiu avatar Jun 09 '18 15:06 bidiu

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 avatar Jun 22 '18 02:06 bidiu

@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.

andi1984 avatar Jun 19 '19 10:06 andi1984

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 avatar Feb 16 '22 10:02 warren-bank

@warren-bank are you interested in merging some of these features back upstream? 🙏

leerob avatar Jul 06 '22 20:07 leerob