Hey All:

I have a file xyz.html in a sub-directory of my www folder, I want to this file to link to a 404 page not found file in the www root folder, when it needs to!

How do i implement this?

2 answers

danwellman 5600
1
point

Do you mean that you want to serve the xyz.html file as a custom 404 page?

This will differ depending on the web server, but it's likely to be Apache. This guide shows how to setup a custom 404 page using htaccess files

Answered about 7 years ago by danwellman
  • Not the only way to do this, but it is a great way, especially if you use virtual hosting. +1 Abinadi Ayerdis about 7 years ago
  • I am not serving the xyz.html file as the custom 404. I have a custom 404 already in the www root folder. Now, i want the xyx.html file which is in a sub-directory of the www folder, to use the 404 file as does every other file in the www folder rodney oleshin about 7 years ago
  • I dont want the xyz.html file automatically re-direct to 404 except a bad request is made from the xyz.html...then it should should the same 404 in root www. rodney oleshin about 7 years ago
o.k.w 2355
0
points

Do you mean linking or redirecting? If it's the redirecting, here's a simple redirecting page which is independent on the type of server you site is hosted on.

The code if placed in /subfolder/xyz.html, will redirect the user to /404.html using 3 methods.
1. Meta-Refresh
2. Javascript
3. Display a link for user to click

These methods are fallbacks for one another in case, some browsers do not support meta-refresh, javascript is turned-off, or user press "esc" key to termintate the auto redirect just before the 404 page is beginning to load.

You can change "/404.html" to any other url (relative or absolute) for other redirecting purposes as well, regradless of the server the site is hosted on.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0;url=/404.html">
<title>Redirecting to .....</title>
<script type="text/javascript">
  location.replace('/404.html');
</script>
</head>
<body>
<p>
Redirecting, please wait or click <a href="/404.html">here</a>
</p>
</body>
</html>
Answered about 7 years ago by o.k.w
  • In what file do i include this code? In the xyz.html file or a new file in the sub-directory? rodney oleshin about 7 years ago
  • I dont want the xyz.html file automatically re-direct to 404 except a bad request is made from the xyz.html...then it should should the same 404 in root www. rodney oleshin about 7 years ago