You are here:  » Modify URL search


Modify URL search

Submitted by ser_seven on Fri, 2006-08-25 07:13 in

When a search is effected it is possible to modify the URL from http://www.mysite.com/search.php?q=telephone to http://www.mysite.com/telephone ?

Submitted by support on Fri, 2006-08-25 10:12

Hello Ser,

It's quite easy to make it work with a leading word search as "search" and a trailing forward slash (because of the way the follow on links work such as /2.html for page 2). To finish the URL on the end of the keyword would require significantly more modification.

To make a URL like:

http://www.mysite.com/search/telephone/

...first, you need to add the following rules to .htaccess

RewriteRule ^search/(.*)/$ search.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^search/(.*)/(.*).html$ search.php?q=$1&page=$2&rewrite=1%{QUERY_STRING} [L]

Next, create a new file to handle the search form submit button and redirect the query to the re-written URL:

searchRedirect.php

<?php
  
require("includes/common.php");
  
header("Location: ".$config_baseHREF."search/".urlencode($_GET["q"])."/");
  exit();
?>

Finally, edit html/searchform.php to change the action attribute of the form to the new script:

<div class='searchform'>
  <form name='search' action='<?php print $config_baseHREF ?>searchRedirect.php'>
    <input type='text' name='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
    <input type='submit' value='<?php print translate("Search"); ?>' />
  </form>
</div>

That should do the trick!

Cheers,
David.

Submitted by ser_seven on Fri, 2006-08-25 11:37

Thank you.
I have tried to make the changes, for example i'm search telephone, i dont have results but have error message 404.

Submitted by support on Fri, 2006-08-25 12:06

Hi Ser,

What URL is in the address bar of your web browser when you get the 404?

It would mean one of two things:

If the URL is:

http://www.example.com/searchRedirect.php?q=telephone

...then it implies that the new script searchRedirect.php cannot be found.

If the URL is:

http://www.example.com/search/telephone/

...then it implies that possibily the code in .htaccess is not correct.

If this doesn't help you can email me the URL to your site and i'll take a look...

Cheers,
David.

Submitted by ser_seven on Fri, 2006-08-25 12:13

Tnk you
Have email !!

Submitted by ser_seven on Fri, 2006-08-25 15:42

Thanks it now works perfectly
You are always very kind and available