Forum Moderators: coopster & phranque

Message Too Old, No Replies

Need an intelligent 404 Perl script for Apache

I want a cgi script that will search case insensitive for matching files

         

Wizcrafts

6:23 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



I recently discovered that Google has erroneously indexed the content above a sub-domain as though it belongs to that domain, which is causing all manner of 404 errors at that domain, from search results. I have created a well documented custom 404 page to show people where the desired content can be found, while still serving 404 and 410 pages to Googlebot, in hopes of fixing the error. Some folks use the links, others give up.

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

milanmk

5:11 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Here is the JavaScript + HTML + Cookie solution for your problem.

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!