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)
This is the GitHub directory I used to deploy (please ignore the commit messages. I am fairly new to using Git, and I got tired):
More contexts:
The deploy summary states:
3 redirect rules processed
All redirect rules deployed without errors.
All stages are completed in the logs.
I added a console log in my main.js: console.log(âCurrent path:â, window.location.pathname); which prints out: âCurrent path: /â with Netlifyâs URL
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: