I am using Firebase Hosting with cleanUrls
.
Firebase Hosting also allows to enforce trailing slashes in all URLs with:
"hosting": {
"trailingSlash": true
}
This will force a 301 redirect if the user requests a page without using a trailing slash. However, I'd like to enforce this redirect only for directories (i.e.: for serving index.html
files).
According the documentation, you can leave trailingSlash
as undefined. This will:
/foo/bar/page
with a 200 (/foo/bar/page.html
)/foo/bar/
with a 200 (/foo/bar/index.html
)/foo/bar
with a 200 (/foo/bar/index.html
)The last part is unexpected, since I'd like to enforce trailing slashes for directories.
How can I enforce a 301 redirection for all directories to enforce a trailing slash only for them? In example:
/foo/bar/page
with a 200 (/foo/bar/page.html
)/foo/bar/
with a 200 (/foo/bar/index.html
)/foo/bar
with a 301 to /foo/bar/
Note there can be many directories so a solution that avoids writing a separate rule for each one is much preferred for maintainability.
Having /foo/bar
return a 404 would be okay too, but 301 is preferred.
As of 2024-04-04, there does not seem to be a solution for this problem:
redirects
in firebase.json
do not work as expected (result in infinite redirections)The issue/feature request was reported to Firebase support.