Redirecting /index.html to root domain doesn't work

Hello!

I just added my site on Netlify, and everything seems to work well, except for one thing.

I’ve read a bunch of similar topics but didn’t help.

I have a very simple static website created with Bootstrap - https://www.radu.link. No site generators, build commands; nothing.

My files aren’t in a public, src, or similar folders. The index.html file is directly in the root, along with the netlify.toml file.

The issue

Currently, the homepage is also accessible via /index.html, creating a duplicate. Even if I have a canonical URL set, I prefer redirecting it to the root /.

So, I added this to the netlify.toml file:

[[redirects]]
    from = "/index.html"
    to = "/"
    status = 301
    force = false

But it doesn’t work.

I also tried:

  • _redirects file;
  • adding force = true;
  • adding the full home URL in to.

I have other things in the file that work fine:

[[redirects]]
  from = "https://compassionate-borg-d88757.netlify.app/*"
  to = "https://www.radu.link/:splat"
  status = 301
  force = true

[[headers]]
    for = "/*"
    [headers.values]
        X-Frame-Options = "DENY"
        X-XSS-Protection = "1; mode=block"

So, the placement of the file is not an issue. Either I’m adding the redirection code wrong, or it’s not possible to perform that type of redirect.

Any help would be appreciated!

Thanks!

@RaduB Welcome to the Netlify community.

Part of the problem is that there is no file at your root. The file that is served is index.html. If you redirect away from that file to no file, no file will be served. That’s the way it works.

If you want it LOOK as if the index.html is not being served, then try turning on Pretty URLs under Asset Optimization in the Build and Deploy section of the site Dashboard on Netlify.

1 Like

Hello!

Got it! Thanks!