PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Peter Kahl   Status 404 PHP Find Best Match Page   README.md   Download  
File: README.md
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: Badges
Date: 5 years ago
Size: 1,552 bytes
 

Contents

Class file image Download

Page not found? Serve an alternative!

Downloads License If this project has business value for you then don't hesitate to support me with a small donation.

When requested page URI is not found in the list of available pages, a 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.

Usage

use peterkahl\NotFoundAlternative\NotFoundAlternative;

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

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