In my main domain directory, in a particular sub-directory, I uploaded a humungous template created product site, with mixed case file names (I know, big mistake). While this has not been a big problem and most search engines have indexed the files with mixed case letters, some people are getting 404s because they are searching for these filenames as all lower case. Since the website has already been indexed from head to toe I am looking for a Perl CGI solution that I can include in a custom 404 page that will search and present case-insensitive alternates for the visitor to choose among. I have tested a PHP script that does this, but it won't let me use my SSI CGI hitcounter as an include.
Does anybody know where I can find such a Perl CGI script to search for a case-insensitive match, or close match, based on the filename and path in a 404 error, and will allow me to include my SSI cgi hitcounter in the html portion?
Thanks, Wiz
1). Make sure the names of all files and folders on your website are written in lowercase.
2). Copy the code below into a new page and save the file as 404.htm, upload the file to the root of your website.
3). Add the following entry to .htaccess
ErrorDocument 404 /404.htm
Code for 404.htm
<html>
<head>
<title>404 Page not found</title>
<meta name="robots" content="noindex,nofollow">
<script language="javascript">
varURL=top.location.href;
function getCookie(NameOfCookie)
{
if (document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin!= -1)
{
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));
}
}
else
{
return null;
}
}
function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null)? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie)
{
if (getCookie(NameOfCookie))
{
document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
strLowcase=getCookie('lowcase');
if (strLowcase!=null)
{
document.write("The page <b>" + varURL + "</b> was not found.<br><br>");
document.write("<a href='/' target='_top'>To homepage...</a><br><br>");
delCookie('lowcase');
}
else
{
setCookie('lowcase',"on",(10/86400));
varURLsmaa=varURL.toLowerCase();
top.location=varURLsmaa;
}
</script>
</head>
<body>
</body>
</html>
I hope it helps!