1

Possible Duplicate:
How to: URL re-writing in PHP?

I want to pass a clean url through search form in index.php(mvc)

ie:

 <form>
    <input type="text" name="search" onClick="if(this.value=='Search') this.value=''"    onBlur="if(this.value=='') this.value='Search'" value="Search"/>
    <button>Search</button>
</form> 

It is sent to index.php and depending on the search parameter i.e $_GET['search'] it is passed to search controller

But instead of index.php?search=xyz i want to pass /search/xyz.

Community
  • 1
  • 1
  • Welcome to Stackoverflow. Please follow the [ask advice](http://stackoverflow.com/questions/ask-advice) you needed to confirm before posting *any* question. Keep in mind that only you want something and you ask yourself how it is programmed does not qualify as a programming question per-se. – hakre Nov 01 '12 at 11:11

2 Answers2

2

If you are using apache read about mod_rewrite you should add rewrite rule which will rewrite /search/xyz to index.php?search=xyz something like:

RewriteEngine on 
Options +FollowSymlinks
RewriteBase / 

RewriteRule ^search/(.*) index.php?search=$1 [R]
Ruben Nagoga
  • 2,178
  • 1
  • 19
  • 30
1

you can do it in the onsubmit function of the form

<form onsubmit="myFunc();">  
..  

in js:

function myFunc(){  
  var search_input = document.getElementById("search_input_id");
  window.location = "http://www.yoursite.com/search/"+search_input.value;}

I am not sure this will work, but this you get the idea.

UPD: in your case: <button onclick="muFunc();">

And in case you meant "how to redirect 'http://www.yoursite.com/search/search_term' to index.php?search=search_term " Ruben Nagoga is 100% right

lvil
  • 4,326
  • 9
  • 48
  • 76