Help needed to redirect /index.html for all pages to their root

Visiting my latest analytics I found that /index.html is available on all pages in the URL structure. I know how to solve this in PHP with .htaccess file but I like to know to solve this in Netlify with the _redirects file using the 301 method.

If anyone has a working solution please let me know, your help is very much appreciated.

Could you elaborate a bit on what you mean, giving real URL’s? I’m looking for something like: “I can load both https://mysite.com/page and https://mysite.com/page/index.html with the same content”

Sure, what I mean, when you visit my website https://www.wheelchairway.com the same URL https://www.wheelchairway.com/index.html is also available, this is for all pages on the website.

Going by search console standards the index.html has the same content as the root UR so this is considered duplicate content. I already have setup a canonical tag in the header but the index.html is still available for people to visit.

Because I use hugo to render my website with Netlify as the backend I was looking for a way to redirect the index.html back to the root of each URL with a 301 redirect.

Something similar like the PHP version like this:

RewriteEngine On
RewriteRule ^index.html$ / [R=301,L]
RewriteRule ^(.*)/index.html$ /$1/ [R=301,L]

Hope that this gives a better understanding of what I am looking to solve.

Hi @lonewolfmedia, you can’t create those types of rules with our redirect engine unless you create a rule for every single index.html file in your deploy. It’s possible to do this programmatically as part of your build, but it’s not something I’ve done with Hugo so I don’t know if it’s natively supported or if you’d have to write your own script to accomplish it. Hopefully a Hugo expert like @budparr or @regisphilibert can answer that.

1 Like