views:

24

answers:

2

Hello,

On a website I have a search form with method get. I would like to know if I can rewrite that url to a better looking one.

For example, now after I submit the search form I get an url like this:

http://www.mywebsite.com/search.php?search_category=0&search_term=Jackson&submit_search=

It would be great if I could make it look like this:

http://www.mywebsite.com/search/Jackson/

Thanks.

+2  A: 
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^/search/(.*)/ /search.php?search_category=0&search_term=$1&submit_search= [L]
Joy Dutta
Ok, but what do I write as an action for the form?
Psyche
If you use POST then no parameter will show on url, only /search.php, which you can change to just /search using .htaccess. If you use GET then the urls will be visible on address bar and you can't change that.
Joy Dutta
A: 

You need to do two redirects as you probably want that the latter is also recognized to represent the former:

# /search.php?search_term=foo to /search/foo/
RewriteCond %{THE_REQUEST} ^GET\ /search\.php\?([^& ]*&)*search_term=([^& ]*)
RewriteRule ^/search\.php$ /search/%2/ [L,R=301]

# /search/foo/ to /search.php?search_term=foo
RewriteRule ^/search/([^/]+)/$ search.php?search_category=0&search_term=$1&submit_search [L]
Gumbo