Any nonexistent path off my domain resolves to homepage

All I have on my site is a single index.html file. When I type in mydomain.com/page1, or /page2, etc. the same page loads. That is, mydomain.com shows the same html as mydomain.com/page1 as mydomain.com/etc.

I’m expected a 404 error when a nonexistent URL is typed in.

I have a CNAME record directing www to mypage.pages.dev. (proxied)
I have an A record with name @ and content 192.0.2.1. (proxied)
I have a redirect rule to redirect the naked domain to www. I used:

When incoming requests match

Field: Hostname
Operator: equals
Value: example.com

Then

Type: Dynamic
Expression: concat("https://www.example.com", http.request.uri.path)
Status code: 301
Preserve query string: :heavy_check_mark:

What’s wrong?

1 Like

In order to get a 404 on nonexistent pages, add a 404.html file at the top level of your site. Then that will be returned with a 404 response code.

The behavior you’re seeing is due to Pages defaulting to a single-page-app (SPA) behavior if you don’t provide a 404 page. See here for documentation.

3 Likes

Thank you.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.