|
How to avoid problems with case-sensitive URL's on UNIX-servers
Create a 404-file that converts the URL into lowercase, using javascript.
A guide for webmasters.
This page in danish
UNIX-servers are case-sensitive - they distinguish between upper-case and
lowercase letters in file names and folder names. So if you move your website
from a windows to a UNIX-server (when you change web host for instance), you
risk getting a certain amount of "Page not found"-errors (404 errors), because
directories and other websites linking to yours sometimes get the cases wrong (typically
writing the first letter of folder names in upper-case etc.).
The solution to the problem: creating a custom 404 page
Usually, you can get access to editing your custom 404-page. Just ask your
web host to set the 404 page to the file 404.htm in the root of your website.
Then, you have two things to do:
- Make sure the names of all files and folders on your website are written
in lowercase
- Copy the html/javascript-code below into a new page in your text editor (Notepad)
- save the file as 404.htm - and upload the file to the root of your website.
It's as simple as that!
<html><head><title>Page not found</title>
<meta name="robots" content="noindex,nofollow">
<script language=javascript>
<!--
// The three functions are general read, set and delete cookie-functions -
// copied from this page: http://www.echoecho.com/jscookies02.htm
// The rest of the javascript is specificallye made for 404-files on casesensitive
servers
// it converts the url til lowercase to see if the reason for the 404 error
is one ore more uppercase letters
// *** NB! - make sure all folder and file names on the website are written
in lower case ***
// Copyright: Forbrugerportalen, 2004
//
http://www.forbrugerportalen.dk/sider/casesensitive404-english.htm
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)
// If the cookie exists, the adress has been converted to lowercase and
still results in a 404-error
{
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
// If the cookie doesn't exist, the URL is converted to lowercase
{
setCookie('lowcase',"on",(10/86400));
// The cookie is set to expire in 10 seconds
// - because
anothere problem with casesensitive URL's can arise again in the same
session
varURLsmaa=varURL.toLowerCase();
top.location=varURLsmaa;
}
-->
</script>
</head>
<body>
</body></html>
|
The script for the 404.htm-file in a js-file...
The script for the 404.htm-file in a zip-file...
Big Webmaster Directory
|
|