Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain

Search:

CA114      CA170

CA668      CA669      Projects


404 PHP handler

The problem: What to do with "404 not found" errors.
These can be quite common because of Linux/Unix case-sensitivity.
  


Case-sensitivity on Linux/Unix server

www.computing.dcu.ie is a Linux server with a case-sensitive file system.
As a result, a direct reference to a file with the wrong case will fail and give "404 Not Found".

Here are various different approaches to this:


User Relationship between URL and file system What happens if case wrong Example of correct case Example of incorrect case
Sysadmins Indirect. Content management system. URL seems to be address of an object in its database. Content management system can implement its own case-insensitive addressing. Correct Incorrect
Normal user's personal webspace Direct 404 Not Found Correct Incorrect
My personal webspace Direct 404 triggered, but I re-direct the error to my own 404 PHP handler program to do case-insensitive and partial matching. Correct Incorrect


This page explains how to make a 404 PHP handler.




.htaccess

The Apache web server allows a "404 not found" error to be redirected to a program (rather than output a standard error page).

Put a .htaccess file in:

$HOME/public_html/.htaccess
This .htaccess file has a line to redirect 404 to a program:
ErrorDocument 404 /~myuserid/404.php





404.php

For the recipe for 404.php see Lab - 404 PHP handler
  


Testing

See the good URL: And try some bad URLs:

This works for my sub-site only: https://computing.dcu.ie/~humphrys/*
It won't work for mis-spellings higher up:




ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.

Wikipedia: Sometimes I link to Wikipedia. I have written something In defence of Wikipedia. It is often a useful starting point but you cannot trust it. Linking to it is like linking to a Google search. A starting point, not a destination. I automatically highlight in red all links to Wikipedia and Google search and other possibly-unreliable user-generated content.