How to use mod_rewrite to rewrite dynamic url for search?
I have a webshop where there is a search field. When I search I am forwarded to a link looking like this:
webshopdomain.com/index.php?route=product/search&keyword=my search phrase
(well, it's more like this: webshopdomain.com/index.php?route=product/search&keyword=my%20search%20phrase )
What do I need to put in htaccess to make this url : webshopdomain.com/search/my%20search%20phrase show the content of the above url?
I have been playing around with this tool ( http://www.webconfs.com/url-rewriting-tool.php ) , but haven't understood how to just grab the search phrase and put that into a static url.
I have also been googling, but in lack of the correct wording, I haven't found the answer.
Thanks :-)
EDIT:
C开发者_开发百科an I use this? (Just thought out, gonna test...)
Options +FollowSymLinks
RewriteEngine on
RewriteRule search/(.*) index.php?route=product/search&keyword=$1
RewriteRule search/(.*)/ index.php?route=product/search&keyword=$1
To avoid recursion, you need to look at the request line:
RewriteCond %{THE_REQUEST} ^GET\ /index\.php\?route=product/search&keyword=([^&\ ]*)&*([^\ ]+)?
RewriteRule ^index\.php$ /search/%1?%2 [L,R=301]
It was quite simple, but had to rearrange the htaccess file itself.
RewriteRule ^search/(.*)$ index.php\?route=product/search&keyword=$1
精彩评论