Index.html permanent in browser address bar

How can I have the homepage as localhost/index.html and not only localhost in the address bar?
If I call the url with index in the browser, it immediately removes the index, having just localhost.

Does uglyURLs fit your needs?

What’s displayed in the address bar is dependend on your HTTP servers response.

You may can configure your server for this.

no, after typing /index.html in addressbar, it disappears. same behaviour. I use uglyurl.
@McShelby I work with netlify, on my other non hugo site it works.

My other pages e.g. contact.html keep the name in the addressbar which makes sense, but index.html does not.

You can open your browsers network tab to see what the server responds.

Without a real URL it’s just guessing.

site is working, you gave the hint.
it is a problem with hugo server on localhost.
so I have to check the local server. Any hints?

I wouldn’t say “it is a problem with hugo server” as you shouldn’t use it in production.

How does this behavior affect your local workflow?

on the linked site, at the bottom the navmenu is highlighted when clicked.
if index.html is not there, it cannot be highlighted, see:

for (var elem of ['index', "contact", 'imprint']) {
    var ahref = document.createElement("a");
    ahref.id = elem
    ahref.href = elem + '.html';
    ahref.textContent = elem[0].toUpperCase() + elem.slice(1)
    bottomnav.append(ahref)
}

let path = window.location.pathname.split('/').pop().replace('.html', '')
const element = document.getElementById(path)
if (element) element.classList.add('active');

This is an issue with your JavaScript and not with the server. Try using this line instead:

let path = window.location.pathname.split('/').pop().replace('.html', '') || 'index'

so if ‘’ is after the hostname, path will use 'index'. I suppose that you do not need .html.
ok, fixed.

If you want it displayed in the search bar, then your current solution is likely correct, but test with different browsers.

However, I don’t think it is generally a good idea to show the file name or extension unless there is a very good reason to do so. Browsers and servers go to great lengths to hide that.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.