I have recently changed my site permalink. Some links are indexed by google and they are in search result. but due to changing of my permalink, now google search send them to error 404 page and that is really bad.
So, instead of showing error404 i want to redirect them to search page extracting keyword from link, for example:
my original link which does not exist now:
http://www.mydomain.com/2013/01/some-title-of-my-site/
Now if it is error404 rewrite them to search page
http://www.mydomain.com/search?q=some+title+of+my+site
Here is my solution: it is working and awesome (no error page :-))
using htaccess to redirect error404 to search page and then set search query by explode url
$urlfrom404 = strtolower($_SERVER['REQUEST_URI']);
$tokens = explode('/', $urlfrom404);
$removeHyphen = strtr($tokens[sizeof($tokens)-2], '-', ' ');