开发者

How to use mod_rewrite to rewrite dynamic url for search?

开发者 https://www.devze.com 2023-02-09 16:36 出处:网络
I have a webshop where there is a search field. When I search I am forwarded to a link looking like this:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号