For some reason, I need to type /index.html in the website URL, which is the case with Netlify CLI and GitHub Pages. However, when I press a new link in my navigation bar (e.g., home.html), Netlify CLI and GitHub Pages still work, whereas Netlify returns to https://candid-sprite-a580ab.netlify.app/.
My _redirects file looks like this:
/* /index.html 200
/home /home.html 200
/stamps /stamps.html 200
(and it is in the root directory, same as index.html)
I would appreciate it if someone could help me debug this. By the way, this is my first time using Netlify. I can provide more information about my issue if needed.
Hi @nathanmartin, thanks for the response. My main issue is that my web app only works when “/index.html” is added to the end of the URL. If the _redirects file isn’t working then I don’t know any other way to fix the issue other than adding:
if (!window.location.pathname.endsWith(‘.html’)) {
if (window.location.pathname === ‘/’) {
window.location.pathname = ‘/index.html’;
} else if (window.location.pathname === ‘/home’) {
window.location.pathname = ‘/home.html’;
} else if (window.location.pathname === ‘/stamps’) {
window.location.pathname = ‘/stamps.html’;
} else {
window.location.pathname = ‘/index.html’;
}
}
to my main.js file which would be bad practice. Can you point me in the right direction? Thanks for the support.
That is my current issue. I linked my Github repository that showed my navigation bar that links to different pages on the web apps are “href=“index.html”, href=“home.html”, etc…” which confused me as to why Netlify would omit the “.html” in the URL. Navigating the home page worked on GitHub Pages and Netlify CLI’s server.
Since having clean URL’s that don’t contain file extensions in the URL is preferable for most people, instead of trying to force them, I’d personally adjust the application so it doesn’t require them.
I’d change all the links from things like /stamps.html to /stamps
I’d adjust the conditionals to check for values like /stamps
If you do want to try and force .html extensions, you’re likely to need to use Edge Functions as per: