Setting up netlify.toml for pretty url

I added a configuration file for the first time.

Added the following code:

[build.processing.html]
  pretty_urls = true

[[redirects]]
  from = "/running.html"
  to = "/running"

I want that URLs never show .html

Both ways did not work.

The netlify.toml is in the root directory.
Anything else which I maybe made the wrong way?

Thank you for your help!

@luisrieke Do you have links that point to your URLs with .html as the suffix?

The default behaviour of Netlify would be that if you had a file /running.html that it would be accessible from /running.

See the note here about a file at /blog.html:

1 Like

Hey @nathanmartin thank you so much for your quick reply :pray:

You’re right, it is accessible but just wondered if there is a way to automatically redirect if there’s a .html in the end of the URL. After all, you’re right, it works like that and I can access everything without .html. But would be even cooler if it’s just not possible to open .html files without a redirect. I thought that is what Asset optimization > Pretty URLs is doing?

Pretty URLs does that, if it’s not working, please share your site name.

Books I like So there’s no redirect for example - no big deal, but if there’s an easy fix that would be amazing!

Hey @luisrieke , I took a look at your site and it does look like the Pretty URLs are working as expected. What I tried was going to your main/home page here [https://luisrieke.com/] and then I clicked on the “running” link, and the URL showed as Luis Rieke - running – is this what you’re expecting?

If you are seeing a specific page or link which is not working as you expect, can you share the URL for that page so we can investigate further?

1 Like

I believe part of the confusion here is whether or not the ‘Asset optimization - Pretty URLs’ is supposed to apply any redirection of a users request for a file.

My understanding, based on the description written under it, is that it scans and changes your HTML to remove references to URLs ending in .html, so if you had a link of href="/about.html", it would adjust your code to href="/about".

What @luisrieke is questioning is that if a user is directly accessing a file with the .html extension in the URL, a file which does exist, is it possible to redirect them to the Pretty URL for that same file.

Example: Going directly to https://luisrieke.com/running.html loads /running.html and doesn’t redirect to /running

I’m not sure I’ve ever tried, but I imagine due to shadowing any redirect for it would need to include force.

So perhaps the equivalent of:

[[redirects]]
  from = "/running.html"
  to = "/running"
  force = true
2 Likes

Thank you so much! I understood and now correctly implemented :raised_hands: