How to Remove HTML File Extensions in URLs Without an .htaccess File

I recently found out how to remove the .html (or .htm) extensions in the URL for HTML files, but without an .htaccess file!

It’s actually pretty simple to do, and I’m surprised I haven’t seen this tutorial anywhere. You just need to utilize index.html files in folders (I think you get where I’m going now) like below.

After you’ve created the HTML file and have all the code in it that you want, go to that page but don’t include the index.html, and watch in amazement as there’s no file extension; or an ending /! (depending on if you include that or not)

If there’s something you didn’t understand or need help with I’ll do my best to help. This was pretty short and I’m not the best at explaining things :stuck_out_tongue:

chiao

8 Likes

This can be achieved with express, which requires nodejs!

let express = require('express');
let app = express();

app.listen(process.env.PORT, (listener) => {
  console.log(`Your app is listening on port ${listener.address().port}`);
});

app.get("/somethingHere", (request, response) => {
  response.sendFile("/app/directory/to/html/file.html")
})

Whats good about that, is that you can set any page, to any url for your project.
You can have a html file called “somethingHere.html” work with “https://yourproject.glitch.me/somethingCompletelyDifferent

Hope this helps!

7 Likes

Hey @Apollyon365, welcome to the Glitch forum!

What @Crazy is showing here is a built-in feature of how Glitch handles static web projects. Nothing about that has changed recently, so this should still work as outlined (and in fact the project mentioned, https://crazz.glitch.me/, seems to work as advertised).

If you’re not seeing the same thing can you provide your project name so we can take a look?

3 Likes

Sure! https://projectgenesis.glitch.me

resolved the issue. But thanks for the info!

when i use this method it brings up the directory for the folder how do i fix this

nevermind i fixed it

I have a Bit of Code Which Does the Same thing sort of but you can name the file anything
And URL Can be Anything:
app.get("/blog", function(req, res) {
res.sendFile(__dirname + “/index.txt”);
console.log(“Received GET”);
});
if you type https://your-project-name.glitch.me/blog it will send that File

if Change blog to something else you can have anything you want
I use it With express to Build a Webpage as well as an API
(Note; when you load a page in a Browser it sends a GET Request )

Thought i show Everyone This Since i don’t Think it would qualify as it Own topic

Good Stuff Though i will say!

Edit: I plan on Making my Webpage go to These URL’s rather then path Find a File

Edit 2: Oh Just so you know you put it in a Javascript File

Hey, I couldn’t find the code to put into my file. It would be really helpful if you could reply with the code to put on my website! Thanks!

I figured it out, but the style.css won’t work!

If the css is in the root folder make the src ./style.css instead of /style.css because it will search the current directory for that file. Hope this helps :).

2 Likes

Thanks… This Helped Me Out! Thanks Again!!! If you want to check out my website.

1 Like


it Just Sends Me This