.htaccess rule for rewriting a GET URL
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/s开发者_StackOverflowearch/Jackson/
Thanks.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/search/(.*)/ /search.php?search_category=0&search_term=$1&submit_search= [L]
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]
精彩评论