views:

72

answers:

3

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
it is not working. Another idea?
Octavian
That's technically correct, but doesn't answer the question of writing the html form so the url is in the desired format.
Pete
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
@Octavian I have the suspicion you're not quite understanding how URLs and URL rewriting works.
Pete
+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
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
It was all about js. Thanks anyway. Best wishes.
Octavian
@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
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