vercel/serve-handler

Omitting files from trailingSlash redirect behaviour

danielstocks opened this issue · 1 comments

Hi,

I'm using the trailingSlash: true option to redirect all my pages from /page to /page/. However this has the unintended consequence of also redirecting /image.jpeg to /image.jpeg/.

After having a look through the ZEIT now spectrum community, someone suggested:

routes [{ 
    "src": "/(((?!\\?|#|\\.|_next).)*((?!\\?|/|#|\\.).))", 
    "status": 301,
    "headers": { "Location": "/$1/" }
 }]

Eg. redirect all paths to trailing slash, unless it's a file (or the _next) folder.

Am I missing something here or isn't this the intended behaviour of trailingSlash?

Thanks in advance

Ok sorry, I'm closing this issue because it seems the problem is with now dev and not serve.

After conducting an experiment on localhost with the trailingSlash configured both in now.json and serve.json I can conclude the following:

running now dev yields:

Screenshot 2020-02-04 at 07 59 59

where as serve results in:

Screenshot 2020-02-04 at 08 00 22

I would say the expected behaviour here is what serve does. I've done a reproducible test here:

https://github.com/danielstocks/trailing-slash-experiments

I think in general my confusion comes from me thinking zeit now uses serve under the hood, maybe I'm mistaken?