GET requests to a subdirectory resolve to `index.html`, not a naked path like the documentation says. This is a significant limitation in terms of using Cloud Storage for static web hosting. My static website resolves to https://example.com/subdirectory/index.html, not https://example.com/subdirectory. In other words, when I navigate to https://example.com/subdirectory I get redirected to https://example.com/subdirectory/index.html. The bucket receives requests via the Global HTTTPS Load Balancer. Please advise.
https://cloud.google.com/storage/docs/gsutil/commands/web#description
1. The main_page_suffix applies to each subdirectory of the bucket. For example, with the main_page_suffix configured to be index.html, a GET request for http://www.example.com retrieves http://www.example.com/index.html but shows http://www.example.com as the URL to the requester, and a GET request for http://www.example.com/photos retrieves http://www.example.com/photos/index.html but shows http://www.example.com/photos as the URL to the requester.
Solved! Go to Solution.
The fix for me was to switch to App Engine for website hosting. Cloud storage is fine for a static website provided there are no subdirectories because if there are you will not be able to get rid of the `.html` in the browsers URL bar. There may be a way to do it with URL rewrites but I was not able to find a timely solution.
I would like the "/index.html" to not be in the address bar of the browser. The documentation says it will not be, but it is.
"a GET request for http://www.example.com/photos retrieves http://www.example.com/photos/index.html but shows http://www.example.com/photos as the URL to the requester."
What has been your Google Cloud Storage configuration? I think I am sensing that if you perform an
HTTP GET https://example.com/subdirectory
You are being served up the content from the object gs://<bucketName>/subdirectory/index.html
This feels right to me. What are you hoping will be returned when you perform a
HTTP GET https://example.com/subdirectory
The fix for me was to switch to App Engine for website hosting. Cloud storage is fine for a static website provided there are no subdirectories because if there are you will not be able to get rid of the `.html` in the browsers URL bar. There may be a way to do it with URL rewrites but I was not able to find a timely solution.
I would like the "/index.html" to not be in the address bar of the browser. The documentation says it will not be, but it is.
"a GET request for http://www.example.com/photos retrieves http://www.example.com/photos/index.html but shows http://www.example.com/photos as the URL to the requester."
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |