-1

I’m running into an issue with my static site, and I could really use some help. Here’s the situation:

Project Structure:

My project is a simple HTML, CSS, and JS site with the following structure:

/my-site/
├── dist1/
│ └── about-us.html
├── dist2/
│ └── contact.html
├── dist3/
│ └── services.html
├── _redirects
├── netlify.toml
└── index.html

Goal:

I want to force all non-.html URLs to redirect to their .html counterparts, like this:

/dist1/about-us ➔ /dist1/about-us.html (301 Redirect) What I Tried:

Disabled Pretty URLs: I have unchecked the Pretty URLs setting in my Netlify dashboard. Added _redirects File: My _redirects file (located in the project root) contains: /* /:splat.html 301

Added netlify.toml:

I also tried using a netlify.toml file with this configuration:

[[redirects]]
from = “/*”
to = “/:splat.html”
status = 301
force = true

Cleared Cache:

Cleared the build cache in Netlify.

Cleared my Cloudflare cache (I’m using Cloudflare as my DNS provider). The Problem:

Despite all this, my non-.html URLs are still not redirecting. Both of these URLs are returning a 200 OK:

https://example.com/dist1/about-us https://example.com/dist1/about-us.html **What I Checked:

The _redirects and netlify.toml files are in the project root. The build logs don’t show any errors related to the redirects. I’ve cleared both Netlify and Cloudflare caches multiple times. There are no conflicting page rules in Cloudflare. What I Need Help With:

Why is Netlify ignoring my _redirects file and netlify.toml configuration? How can I force the .html redirects to work consistently across my site? Any guidance would be greatly appreciated!

Thanks in advance for your help!

1 Answer 1

0

This is a interesting situation, here's what I would do about it.

In Netlify, you can override the 404 page by creating a 404.html file. With a little bit of JavaScript you could check the path of the page and redirect the user if necessary to the right HTML file. And, of course, if there is no page to redirected to you would show 404 page.

It would be some pretty simple code, you'd just essentially be doing:

If page contains /dist1 and does not end in .html, redirect to /dist1/about-us.html (repeat this for all of them)

This isn't the best solution but since this isn't a built-in feature I would do this. If you need help writing the code tell me and I'll help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.