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
Chaika
Chaika13mo ago
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 …
Discape
DiscapeOP13mo ago
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
Chaika
Chaika13mo ago
ahh, you're saying right now it's sending index.html even for Pages which do exist?
Discape
DiscapeOP13mo ago
yes
Chaika
Chaika13mo ago
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
Discape
DiscapeOP13mo ago
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
Chaika
Chaika13mo ago
What's your website url, and are you using a framework like Sveltekit, Nextjs, etc?
Discape
DiscapeOP13mo ago
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
Chaika
Chaika13mo ago
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
Discape
DiscapeOP13mo ago
yeah i was using the wrong version of hugo my bad solved
Want results from more Discord servers?
Add your server