Hi David,
Looking to change search display from http://www.domainname.co.uk/search.php?q=widgets to http://www.domainname.co.uk/widgets on the fly when widgets are searched for.
I'm almost certain I came across a thread to do this before but can't seem to find it. If it hasn't been done before, is it possible ?
Many thanks
Adrian
Hi Adrian,
It's relatively straight forward, first you need in .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?q=$1 [L]
...but then a method to redirect to the /keyword version of the page when submitting a new search needs to be implemented. The easiest way is to add a hidden field to the search form (redir), so in html/searchform.php look for the following code on line 4:
<input type='submit' value='<?php print translate("Search"); ?>' />
...and REPLACE this with:
<input type='hidden' name='redir' value='1' />
<input type='submit' value='<?php print translate("Search"); ?>' />
Then finally, at the top of search.php, immediately after:
require("includes/common.php");
...add the following code:
if ($_GET["redir"])
{
header("Location: /".$_GET["q"]);
exit();
}
That should do the trick!
Cheers,
David.