Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

CA170      CA318      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

It is common to have your website on a Linux/Unix server with a case-sensitive file system.
On such a server, a URL may directly reference a matching file on the disk.
But then typing that URL with the wrong case will fail and give "404 Not Found".

Here are different approaches to dealing with URL case-sensitivity:


User Relationship between URL and file system What happens if case wrong Example of correct case Example of incorrect case
Normal user's personal webspace on:
 www.computing.dcu.ie 
Direct 404 Not Found Correct Incorrect
Sysadmins running department webspace on:
 www.dcu.ie 
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
My own website:
 humphryscomputing.com 
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


To summarise, I set up for my site a case-insensitive site using a 404 PHP handler.

You can try this out on your own account on:

 student.computing.dcu.ie 
Recipe is as follows.



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:

$HOME/public_html/.htaccess
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




404.php

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


Testing

See the good URL: And try some bad URLs:




Apache module

  

ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 200 G VPS server.

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.