Skip to content
Sign upLog in
← Back to Community

How to hide file name extensions from your website url!

Profile icon
ThatGhost

We all know that repl doesn't support .htaccess but there are still ways to work around the issue!

First, make a new nodejs repl, then install express and fs.

Run npm i express in the shell to install express.
Run npm i fs in the shell to install fs.

Next, after you require these, your going to write the express code below.

const express = require("express"); const fs = require("fs"); const app = express(); app.use((req,res,next) => { res.append("Access-Control-Allow-Origin", "*"); res.append("Access-Control-Allow-Headers", "Control-Type"); res.set("Access-Control-Expose-Headers", "*"); next(); }); app.use(express.static(__dirname + "/public/"));

Now, add a folder named public to your project, and add your html and css, if you need to add javascript (for the site) too do so in that folder.

app.get("/", (req,res) => { fs.readFile("public/file.html", function(err,data){ res.writeHead(200, {"Content-Type": "text/html"}); res.write(data); res.end(); }); });

Now say you have a terms of service file, you can just do something like this!

app.get("/terms", (req,res) => { fs.readFile("public/file.html", function(err,data){ res.writeHead(200, {"Content-Type": "text/html"}); res.write(data); res.end(); }); });

Make sure to replace file.html with your file name.

That's all! You have to do this for **every single file, ** although you could probably make a system which does it for you!

Also in your <a></a> tags make sure you set href to what is shown in the app.get statement.

<a href="/terms">Terms of service!</a>
Voters
Profile icon
Mawyff
Profile icon
Cu3t0m
Profile icon
ThatGhost