How can we remove .html from our pages?
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)
Voters
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
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")})
@BrysonVan1 Thanks! it works, but how do we link our 404 page?
@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.
@BrysonVan1 It works, Thanks!