Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Online coding site: Ancient Brain

coders   JavaScript worlds


CA170      CA2106      CA686      CA686I

Online AI coding exercises

Project ideas

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.

ErrorDocument in .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:

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

Help files:

Some notes:

Conclusion, use this:
ErrorDocument 404 /~myuserid/404.php
ErrorDocument 403 /~myuserid/404.php


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


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:

Apache module


ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.