PHP Classes


Recommend this page to a friend!
  Classes of Peter Kahl  >  Status 404 PHP Find Best Match Page  >  README  >  Download  
Role: Documentation
Content type: text/plain
Description: README
Class: Status 404 PHP Find Best Match Page
Find best match URL when accessing an invalid page
Author: By
Last change:
Date: 3 years ago
Size: 959 bytes


Class file image Download
Status 404 Find Best Match Page

This PHP class catches all "soft errors 404" and finds the closest (best,
most likely) candidate page name (URI) from a list of pages that exist.

Soft error 404 is defined as one that is initiated by this PHP script:
* The script compares the current request against a list of existant pages.
* If match isn't found (soft error 404), a closest match is found.
* The script replies with status 302 (permanent redirect) to the existant

Hard error 404 is initiated by HTTP server.

Functionality of this class depends on properly set up rewrite inside
htaccess (or nginx configuration) file.

NGINX example:

server {
	error_page  404  /index.php?page=/404/;
	location / {
        rewrite ^(/[a-zA-Z0-9\-/\s]*)$   /index.php?page=$1   last;