Cloudflare serving index.html on every path
Hi! I have a cloudflare pages deployment that has some static pages, but is mostly an SPA. When I try to access for example a .xml file in the site, it works. But when I try to access a .html file, it just sends index.html
10 Replies
Single-page application (SPA) rendering If your project does not include a top-level 404.html file, Pages assumes that you are deploying a single-page application. This includes frameworks like React, Vue, and Angular. Pages’ default single-page application behavior matches all incoming paths to the root (/), allowing you to capture URLs like /about or /help and respond to them from within your SPA.https://developers.cloudflare.com/pages/platform/serving-pages/ Create a 404.html at root if you don't want that SPA behavior
Serving Pages · Cloudflare Pages docs
Cloudflare Pages includes a number of defaults for serving your Pages sites. This page details some of those decisions, so you can understand how …
I want it to resolve to index.html when there isn't a file to serve
but I want it to serve a file if it exists
ahh, you're saying right now it's sending index.html even for Pages which do exist?
yes
It shouldn't be doing that, what's your Uploaded Files look like?
There is a bit of magic as well with that:
Route matching If an HTML file is found with a matching path to the current route requested, Pages will serve it. Pages will also redirect HTML pages to their extension-less counterparts: for instance, /contact.html will be redirected to /contact, and /about/index.html will be redirected to /about/.It should just strip the extension and work though
It actually does work in some places. For example, /blog/ correctly resolves to /blog/index.xml
but /blog/index.html resolves to /index.html
and /blog/posts/ resolves to /index.html too, even though /blog/posts/index.html exists
What's your website url, and are you using a framework like Sveltekit, Nextjs, etc?
It's a statically generated SvelteKit and Hugo site
wait a sec
i might be doing something wrong
i need to do more investigating to see where the issue is
If you navigate to the deployment in the dashboard you can see all of the uploaded files
Magic Link: https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/:pages-deployment/files
yeah
i was using the wrong version of hugo
my bad
solved