PHP Classes
elePHPant
Icontem

Status 404 PHP Find Best Match Page: Find best match URL when accessing an invalid page

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2013-08-25 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 450 All time: 5,827 This week: 951Up
Version License PHP version Categories
status-404-find-best 1.0.0GNU General Publi...5.0HTTP, PHP 5, Text processing, Artific...
Description Author

This class can find best match URL when accessing an invalid page.

It takes the list of URIs of valid pages and finds the page that matches better the URI of the current request when it is not valid.

The class redirects the browser to the best match page URL.

Innovation Award
PHP Programming Innovation award nominee
September 2013
Number 5


Prize: One copy of the Zend Studio
Some times users access inexistent pages because they mistyped the URL. In that case it would be better to try to fix the URL for the user instead of just say it is wrong.

This class can attempt to fix incorrect URLs using a list of URLs that are known to be correct.

Manuel Lemos
Picture of Peter Kahl
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 5 packages by
Country: Hong Kong Hong Kong
Age: ???
All time rank: 11565 in Hong Kong Hong Kong
Week rank: 401 Up2 in Hong Kong Hong Kong Up
Innovation award
Innovation award
Nominee: 2x

Details
Status 404 Find Best Match Page

https://github.com/peterkahl/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
  page.

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;
    }
}

//----------------------------------------------------------------------

  Files folder image Files  
File Role Description
Plain text file class.status-404-f...best-match-page.php Class The class
Plain text file index.php Example Example of usage
Plain text file README Doc. README
Plain text file CHANGELOG Data Change log
Plain text file LICENSE Lic. License

 Version Control Unique User Downloads Download Rankings  
 0%
Total:450
This week:0
All time:5,827
This week:951Up
User Comments (1)
good
2 years ago (Rahul Shambharkar)
80%StarStarStarStarStar