Skip to content
← Back to Community
How can we remove .html from our pages?
Profile icon
Xenity

So me and @A1PHA1, want to remove .html from our pages. We are using a node server but can't figure out how to do it, we have tried things but they haven't worked. Any help is appreciated (we also want to link our 404 page, link to repl: https://replit.com/@TeamBlabbr/Blabbr?v=1)

Answered by BrysonVan1 [earned 5 cycles]
View Answer
Voters
Profile icon
Xenity
Comments
hotnewtop
Profile icon
BrysonVan1

To remove the .html from your pages, move your html files out of the public folder and into another folder (I like using one called views but its up to you). Then, create routes to each one of your pages using app.get("/route", (req, res) => {res.sendFile(__dirname + "/views/pagetoshow.html")})

Profile icon
Xenity

@BrysonVan1 Thanks! it works, but how do we link our 404 page?

Profile icon
BrysonVan1

@Xenity At the bottom of your code (but above server.listen), do the same app.get thing but have * as the route. Make sure this is at the bottom of your code or literally all of your pages will return 404.

Profile icon
Xenity

@BrysonVan1 It works, Thanks!

Profile icon
Hyderite

although @BrysonVan1 's answer is also correct, there is a simpler way to remove .html.
You simply have to change this
index.html
about.html
products.html
terms.html
to this
index.html
about/index.html
products/index.html
terms/index.html.

source: https://stackoverflow.com/questions/5730092/how-to-remove-html-from-url

image