You are here:  » Changing the way Search is displayed

Support Forum



Changing the way Search is displayed

Submitted by paddyman on Tue, 2009-05-12 06:41 in

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

Submitted by support on Tue, 2009-05-12 08:52

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.