How it works...

For our 404 errors, we override the default NGINX 404 page to a custom location (error_page 404 @404page;). The reason we need to use a custom location is so that we can rewrite the URI and arguments.

Within our @404page location, we rewrite the URI and arguments to the search page (/search.php?uri=$uri&$args), so that they can be used as variables. For example, if we make a call to /oldpage/index.asp?id=44, it will send this to /search.php as the following variables:

Lastly, we also include a try_files call to ensure that any missing PHP files are also rewritten to the search.php file.

The search.php file could include the ability to have a lookup table or it could incorporate a database search to do a fuzzy search and either automatically redirect or simply present options to the user.