Same in the layouts dir then I created two 404.html and .md files one of them in the root of main/404.html and other in rjis/404.html. The .md files has this frontmatter in them
---
title: "404 Not Found"
layout: "404"
---
I also created a netlify.toml file and put this code in it.
[[redirects]]
from = "/main/*"
to = "/main/404.html"
status = 404
[[redirects]]
from = "/rjis/*"
to = "/rjis/404.html"
status = 404
https://gleaming-fenglisu.netlify.app, Also one more thing home page, stops working from time to time. like it works fine no local host, but not on netlify. The other pages work fine.
You really should just check what files are being output by your build, as it’ll shine a bit of a light on it.
As you’ve shown in the screenshots you provided while I was writing my reply, your files are actually called index.html and are in folders called 404, that isn’t what the Netlify redirects documentation states, nor what your redirect rules point to.
So you’ll need to make things align, by either changing where they output, or where the redirect points.
But I am kinda still where I started from, if there’s an actual 404 it only shows the page from main/404 and not the other.
What I am trying to do if is there’s an 404 on main or / it shows the 404 from main/404 but if there’s an error on url/rjis/ it show the 404 from rjis/404 kinda like this
@YasirRWebDesigner Checking that change, it should resolve to the same thing I mentioned, I just manually resolved to where the files actually are.
E.g. There’s no file at /main/404/, the file is at /main/404/index.html
Could you try with them pointed at the actual files?
(I can’t say if it’d make any difference, but it seems worth a shot)
I also spot that the Netlify documentation itself only ever mentions the files being explicitly called 404.html, which is how I’ve done it in the past, so it may actually be a requirement.
oh I think I kinda get your point, you are saying the netlify only looks for a page called 404.html and my files are 404/index.html but according to the docs shouldn’t work for urls as well?
# Show a custom 404 for this path
[[redirects]]
from = "/ecommerce"
to = "/store-closed"
status = 404
so technically
[[redirects]]
from = "/rjis/*"
to = "/rjis/404/"
status = 404
@YasirRWebDesigner I’d expect it to work yes, but as I said earlier, it seems worth a shot try some basic things, even though it may make no difference at all.
Especially when you factor in that a URL of /store-closed wouldn’t resolve to /store-closed/index.html, but to /store-closed.html
If the redirect is pointed at another URL, there’s clearly other handling that needs to fire.
okay, so here’s what did and now it’s according to what you were saying to have a 404.html file in main and rjis. slightly different the main/404.html is in layouts/404.html like normal 404 file.
First in the .md files I removed the url: frontmatter and added
aliases:
- /rjis/404.html
what this does is on top of a file in 404/index.html it also creates an other file named 404.html in the rjis dir.
It’s working finally after 20 commits and 24 hours, it’s working… T^T
1. Create two 404.html files 1st in layouts/ 2nd in your other dir for me rjis/.
2. Create .md file content/rjis/404/_index.md
---
title: "404 Page Not Found"
layout: "404"
---
3. Add to netlify.toml file
[[redirects]]
from = "/rjis/*"
to = "/rjis/404.html"
status = 404
[[redirects]]
from = "/*"
to = "/404.html"
status = 404
Edit: It is important that you name them 404.html otherwise it won’t work, the .md in 404 dir don’t use fontmatter like url it won’t work, if there are multiple files listed as 404 in the same 404 or if they aren’t in the right place. At least this what I think is going on here