Infinite redirect on trailingSlash: false and cleanUrls: false
Repro: If I have foo.html and foo/index.html, with trailingSlashes false and cleanUrls false, when I go to /foo or /foo/ it will trigger an infinite redirect between /foo and /foo/.
Infinite redirects even happen when there is no file with the same name as the folder (ie. foo.html is not required to reproduce this issue). The following steps are already sufficient to reproduce the issue:
- Set
trailingSlash: false, cleanUrls: false,(cleanUrls: falseis the default) - Create
public/foo/index.html - Visit
/fooor/foo/-> both lead to infinite redirects
I can confirm and reproduce @a-xin's issue. Unfortunately this also affects Firebase Hosting and firebase-tools.
@laurenzlong, @firebase-ops and @mbleigh may I ask you that are you planning to resolve this issue?
Also with trailingSlash set to false and cleanUrls set to true folder redirects to folder/ and I can visit either of them and I am getting the following error in the console:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:471:11)
at Responder.handleRedirect (node_modules\superstatic\lib\responder.js:146:12)
at Responder._handle (node_modules\superstatic\lib\responder.js:62:19)
at Responder.handle (node_modules\superstatic\lib\responder.js:43:15)
at node_modules\superstatic\lib\middleware\files.js:32:30
at _run (node_modules\superstatic\lib\activator.js:58:16)
at node_modules\firebase-tools\lib\hosting\initMiddleware.js:25:7
at _run (node_modules\superstatic\lib\activator.js:58:16)
at node_modules\superstatic\lib\responder.js:45:7
at tryCatch (node_modules\rsvp\dist\rsvp.js:525:12)
I have the same problem:
"cleanUrls": true, "trailingSlash": false
"trailingSlash" does not work.
Test website: https://aikode-gatsby.firebaseapp.com/page-2/ does not redirect to https://aikode-gatsby.firebaseapp.com/page-2 (without slash)
With the code that's now in master (from PR #256), I think we'll resolve this issue (specifically in firebase-tools, when we push a set of new releases including the changes).
If you'd like to take this new code out for a spin, you can make a local clone of firebase-tools, in that clone do npm i firebase/superstatic#master, and then use firebase-tools/bin/firebase to run serve in your project's directory.
This behavior fix is something that is top of mind for us right now, so we hope to have an update shortly :)
This is my current workaround:
{
"trailingSlash": false
, "cleanUrls": true
, "redirects": [
{
"source": "/folder/"
, "destination": "/folder"
, "type": 301
}
]
}
It works even with the error.
@laurenzlong, @firebase-ops @mbleigh However today my live Firebase Hosting instance got into a redirect loop. So those routes went down. I didn't deployed any changes recently. Rolling back to a previous version and than rolling back to the current one resolved the issue. Probably temporarily.
@laurenzlong This incident happen again, but this time it occurred right after deployment. This time the previous roll back workaround didn't resolved the issue. Fortunately doing another deploy with no changes at all resolved the issue. Probably temporarily.
@laurenzlong It was temporary. Now unfortunately the route is down again.
It goes down after a couple of minuets once I deploy and I didn't made any changes recently to the firebase.json file.
Can you email me directly (bleigh at google) with the specific details of what's happening?
On Mon, Aug 13, 2018, 5:32 AM Erik Engi [email protected] wrote:
@laurenzlong https://github.com/laurenzlong It was temporary. Now unfortunately the route is down again.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/superstatic/issues/235#issuecomment-412502167, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAD_pSnlMLoUn2G5cNkIULFPAixutchks5uQXHUgaJpZM4OoyWV .
@mbleigh I have sent you an email.
It looks like that the previously mentioned workaround only works locally and it is no longer somewhat consistently working on a production Firebase Hosting instance. I assume since the release of Superstatic version 6.0.0.
As of right now the following setting works on a production Firebase Hosting instance as well:
{
"cleanUrls": true
}
It works as described in the README. Plus what is not currently mentioned in the README is that it does redirect to a route without a trailing slash. For example: folder/index.html -> folder (and not folder/) or folder.html -> folder (and not folder/)
This is the desired behavior at least for me, but it was probably not intentional.
Note: With this setting both folder/ and folder is available without any redirection.
Adding a below like redirect works locally, but a production Firebase Hosting instance gets into a redirect loop after couple of minutes once deployed.
{
"cleanUrls": true
, "redirects": [
{
"source": "/folder/"
, "destination": "/folder"
, "type": 301
}
]
}
In my opinion this redirection is correct and it should work on a a production Firebase Hosting instance as well.
Note: Setting trailingSlash to false doesn't do the above defined redirection (It doesn't redirects folder/ to folder.). This setting is probably for something else or it is not working as expected.
In my case it seems like it does nothing.
Note: I still get the previously mentioned error in the console, which is probably not or at least not closely related to this issue.
@kireerik are you still seeing these issues? The infinite redirect as described in the original issue has been fixed, and I'd like to close this out. If you have a specific question about the interactivity of a few of these properties, maybe it's best to open a new issue. I also don't see the error message you previously mentioned in the latest version of superstatic.
in v6.0.1:
"trailingSlashes": false,
"cleanUrls": false,
:~ » curl -I localhost:5000/foo
HTTP/1.1 301 Moved Permanently
Location: /foo/
Content-Type: text/html; charset=utf-8
Date: Thu, 27 Sep 2018 20:48:07 GMT
Connection: keep-alive
:~ » curl -I localhost:5000/foo/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 15
ETag: 3bdb82544a82772f67842fe18e97439a
Last-Modified: Fri, 15 Jun 2018 15:41:41 GMT
Date: Thu, 27 Sep 2018 20:48:10 GMT
Connection: keep-alive
@bkendall Yes, I can confirm that as of firebase-tools version 5.0.0 the redirects are working in production as well.
The redirects are still needed to achieve the effect I would expect from setting trailingSlashes to false. It seems that the trailingSlashes option has no effect at all currently. Can you confirm this?