I'm trying to serve a static website using GCP and Google Cloud Storage. I have done everything specified here https://cloud.google.com/storage/docs/hosting-static-website
Say I have the following file structure:
- index.html
- folder
- index.html
- another.html
I enter www.example.com/folder
.
It redirects to www.example.com/folder/index.html
=> index.html is undesired
But if I enter www.example.com/folder/
, it doesn't redirect and serves correctly the index.html page transparently.
How do I prevent the first behavior? Or automatically add a trailing slash?
Thanks!
As per https://cloud.google.com/storage/docs/hosting-static-website this behaviour is intended. As to whether it's desirable, that's a bigger issue.
For example, say you set the MainPageSuffix of your static website to index.html. Additionally, say you have no file named directory in your bucket www.example.com. In this situation, if a user requests the URL http://www.example.com/directory, Cloud Storage attempts to serve the file www.example.com/directory/index.html. If that file also doesn't exist, Cloud Storage returns an error page.
The MainPageSuffix also controls the file served when users request the top level site. Continuing the above example, if a user requests http://www.example.com, Cloud Storage attempts to serve the file www.example.com/index.html
Unfortunately I do not know of a way to automatically add the trailing slash. Perhaps you could add a message on index.html to the tune of "Did you mean to go to http://example.com/thisfolder/ instead of http://example.com/thisfolder/index.html", but this is something of a kludgy workaround.
Firebase Hosting might be easier than using a bucket, because one can define rewrite rules there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With