Rewrites issue
Hello,
I have this configuration for my rewrites:
"rewrites": [ { "source": "/**", "destination": "/index.html" }, { "source": "/logout", "destination": "/logout.html" } ]
I'm trying to use index.html for every route but not for logout. I tried many options, but can't really make it work.
Thank you
Same thing here. Rewrites works perfectly except when the URL points to index.html, when it starts generating weird redirects. I would say rewrites are really broken right now.
Directory Layout
index.html
foo.txt
serve.json
serve.json
{
"rewrites": [
{ "source": "/foo/bar/:path*", "destination": "/:path" }
],
"trailingSlash": true
}
Observed behavior
GET /foo/bar/foo.txt: 200 OKGET /foo/bar/index.html: 301 Moved Permanently (whaat?), redirects to/foo/bar/index, then to/foo/bar, then to/foo/bar/.GET /foo/bar/: 404 Not Found
Without trailingSlash, I get the 404 Not Found one step earlier, when hitting /foo/bar. But that one feels normal since it doesn't match any rewrite rule.
@ionutcirja if the rewrite sources are non-overlapping, it seems to work. (Not sure if this helps in your case...) This worked for me as expected:
{
"cleanUrls": false,
"rewrites": [
{ "source": "logout", "destination": "/logout.html" },
{ "source": "app/**", "destination": "/index.html" }
]
}
Looking at the applyRewrites function, it's not really obvious how it works. (early out + loop + recursion...)
shameless self-promotion alert:
this feature is available in my @warren-bank/serve fork of serve
both redirects and rewrites support an optional boolean terminal attribute, which will prevent any additional rules from being processed.
..in relation to your example, process the 'logout' rule before the catch-all.. and mark it terminal