PHP Classes


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



Class file image Download

Not Found Alternative

(formerly 'Status 404 Find Best Match Page')

When requested page URI is not found in the list of available pages, closest matching page URI will be found and a redirect header will be returned.

This package will please all those concerned with search engine optimisation (SEO), and in situations where URIs often change; it eliminates the need for URL rewrites.


use peterkahl\NotFoundAlternative\NotFoundAlternative;

# For testing purposes, we set these; otherwise to be omitted.
$_SERVER['REQUEST_URI']     = '/contatcus?lang=en-us';
$_SERVER['HTTP_SCHEME']     = 'https';
$_SERVER['HTTP_HOST']       = 'www.blah.sample';
# ---- End of testing variables ----

$notfoundObj = new NotFoundAlternative;
$notfoundObj->AvailableURI = array(
# The script serves Status 301 permanent redirect header
# and Location header 'https://www.blah.sample/contact-us?lang=en-us'
# and then exits.