MEANT FOR URL REWRITE SITES! (sorry for the caps)
A non URL Rewrite site would not have any use for this. Since the pages would be by their number ID, which is useless to search on.
Concept:
Since I couldn’t find a dynamic search that worked with URL Rewriteable pages, I made it myself. ^_^
This very simple snippet I was made for my own convenience, so if you go to
http://nimja.com/random
The page doesn’t exist, go to the 404 and it does a search for you. Let’s get on with it.
Snippet: (put this in a snippet called:
SetSearch)
<?php
/* SetSaerch snippet.
* Usage: simply place this code in a snippet and use it on the 404 page:
* [!SetSaerch!]
* [!AjaxSearch? &AS_showForm=`0` &ajaxSearch=`0`!]
* NOTE: An AjaxSearch call NEEDS to be included after this call for this to have any effect.
*/
if (!empty($_GET['q']) && empty($_GET['AS_search'])){
//Strip slashes and dashes to spaces and do an URL decode to clean up the query.
$cleanQuery = strtr(urldecode($_GET['q']),"/-"," ");
//Remove any words consisting of only 1 or 2 letters due to AjaxSearch's limit
$cleanQuery = preg_replace('/\b\w{1,2}\b/','',$cleanQuery);
//Find position of last . (in case of multiple .'s)
$dotPos = strrpos($ssStrQuery,".");
//If there is a . involved (so a possible extentsion)
if ($dotPos !== false){
//Remove everything after (and including) the last .
$cleanQuery = substr($cleanQuery,0,$dotPos);
}
//Set the POST value that AjasSearch uses.
$_POST['search'] = $cleanQuery;
}
//Return empty handed (post contains search value)
return null;
?>
The page code: (put this on the page you want to use it on, and have the configuration set to use this as the 404 page.
[!SetSearch!]
[!AjaxSearch? &AS_showForm=`0` &ajaxSearch=`0`!]
The result:
On your 404 page you actually get dynamic search results using the standard AjaxSearch that just make your site look incredibly nifty. And it only takes 1 minute to install. What more could you want?
Also, it supports multiple result pages. (quick fix 2 minutes ago)
Can easily be adjusted for many other scenario’s as well.
ps. It could be made a whole lot better, supporting chunks and all kinds of different things. This is just a very simple example of how to use URL rewriting into a dynamic page.
pps. Updated with the short word fix.