How do I Get Rid of the .html extension?
How do I do this on repl.it? I have tried adding a .htaccess file but it doesn't work. Any way to do this?
if you mean in the url, you can set up a Node.js http server and handle requests by writing html files to specific urls. for example, if the request has url link/home
, you can write the file home.html
to it
@MrEconomical How would I go about doing this for every .html page in the coding language html,css,js?
@JordanDixon1 ideally, you would have a finite amount of pages you want in your website. you can manually check each url and then give the corresponding html page.
@MrEconomical How would I do that?
@MrEconomical He could use middleware maybe?
@Vandesm14 middleware?
@JordanDixon1 Like this
app.use((req, res) => {
res.redirect(req.path.replace('.html', ''));
});
It checks every route instead of a single one.
@Vandesm14 How would I implement this in html,css,js?
@Vandesm14 Do I have to create a whole new nodejs repl?
@Vandesm14 How would I implement the html part?
@JordanDixon1 Mat just answered it.
You can create a folder with the name of the path you want (ex. myhtml) and then insert a file called
index.html
inside it (it must have this exact name) with all the html you want. Then when you go to ...repl.co/myhtml it should show the html you put in index.html.@mat1 didnt work.
@JordanDixon1 That's weird, it works fine for me. Here's an example Repl: https://repl.it/@mat1/FlickeringJaggedRuby https://flickeringjaggedruby.mat1.repl.co/myhtml/
@JordanDixon1 Oh, the issue is that you didn't name the file inside the folder "index.html". (It uses the folder name for the url if you do this)
@mat1 Ohhhh. I had to rename the file index.html instead of page2.html thanks.