I want to know if it's possible to create a GET form that has as action "search.php?what=bla bla" and in the url bar it shows "search/bla bla" . Then I can handle the search file and explode the search terms, but what is the rewrite rule?
+1
A:
You can put the following code in your .htaccess file:
RewriteEngine on
RewriteRule ^/search/(.*)$ /search.php?what=$1
Patrick
2010-07-07 03:57:20
it is not working. Another idea?
Octavian
2010-07-07 04:24:05
That's technically correct, but doesn't answer the question of writing the html form so the url is in the desired format.
Pete
2010-07-07 04:24:20
I tried with a simple url so I can test: http://localhost/search.php?what=wtf . It didn't worked. The form it's this:<form action="search.php" method="GET"><input type=text id=what name=what /><input type=submit value="go" /></form>
Octavian
2010-07-07 04:25:57
@Octavian I have the suspicion you're not quite understanding how URLs and URL rewriting works.
Pete
2010-07-07 04:31:18
+1
A:
You can't create the form to generate the URL in the desired format, and it's not of any use search engine wise.
However, when for example listing 'recent searches', you can list the URLs in the format search/bla%20bla
, and use the rewrite rule given by Patrick.
Be very careful with your input validation BTW.
Pete
2010-07-07 04:28:26
I just wanna give the users a more confortable experience. Check http://trilulilu.ro and test that's site search. Do you think any javascript is involved and I should take that way?
Octavian
2010-07-07 04:33:56
@Octavian What is more comfortable in this experience? less than 5% of users even notice an address bar. Others type even domain address in the search engine prompt.
Col. Shrapnel
2010-07-07 04:56:39
A:
I discovered a way to do what I wanted to do.
<form action="search.php" method="GET" id="form23" name="form23">
<input type=text id=what name=what />
<input type=button value="go" OnClick="document.location='cauta/'+document.form23.what.value;" />
</form>
But remember this is only for people's browsing experience.
Octavian
2010-07-07 04:47:32