how do I add a 404 page to my Repl website?
Is your repl run server side? Or is it just an html, js, and css repl?
I know you can do it using Python.
Add a 404.html file if you’re using HTML/CSS/JS
In a pure HTML/CSS/JS Repl, a 404.html
has never worked for me. I use either Python Flask or NodeJS to do that. The links I included are to example sites that I made. If you don’t know Python, I highly recommend using the NodeJS one as you don’t have to really do anything with the NodeJS to make it work.
If you’re using flask (or possibly some other things that are not run server side), you can create a 404.html page.
If you’re using anything else, you will need to tell the server to use the page when a url is not found. Idk if this is how it works on replit, but you can go in the .htaccess
file, add:
ErrorDocument 404 /path/to/your/404/page.html
then, save it to the root directory, and now your Error 404
page should come up once an invalid site url is entered.
I am not great at server stuff, but I hope this helps!
don’t work in replit
yah well it dose work but not in replit
What are you using to host the website? A HTML/CSS/JS repl?
I’m using html, js, and css
Well if you want a 404 page, you are going to need to learn how to make a server. Personally, I would use node.js to make the server side code, and you can do it like this.
Create a nodejs repl.
index.js
const express = require("express");
const app = express();
// handle requests to main page yoursite.repl.co
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
// handle requests to yoursite.repl.co/info
app.get("/info", (req, res) => {
res.sendFile(__dirname + "/info.html");
});
// handle any other requests (404)
app.get("*", (req, res) => {
res.sendFile(__dirname + "/404.html");
});
app.listen(3000);
Create an index.html, info.html (or whatever other page you want), and a 404.html
There are a few other ways, but this way is the easiest to explain.
Sorry. I never tested it