簡體   English   中英

將查詢字符串重寫為另一個查詢字符串

[英]Rewriting query string to another query string

我需要獲取傳遞到我的網站的搜索網址,如下所示:

 /index.php?keyword=47174&Search=Search&Itemid=1&option=com_virtuemart&page=shop.browse

並將它們改為:

 /catalogsearch/result/?q=47174

我需要在“keyword =”之后取值,忽略&符號后面的所有內容,然后將它放到第二個url之后?q =

這是我到目前為止所提出的:

 RewriteCond %{QUERY_STRING} ^keyword=([a-z][0-9a-z_]+)$
RewriteRule ^index\.php$ /catalogsearch/result/ [L]

但是,這也會在url的末尾打印keyword =,不打印q =或清除&之后的所有內容

我怎樣才能解決這個問題?

你會想要你的RewriteRule像:

RewriteRule keyword=([0-9a-zA-Z_]+) /catalogsearch/result/?q=%1 [L]

括號內的所有內容都將替換右側的%1

您可以使用以下內容:

RewriteRule ^index\.php$ /catalogsearch/result/?q=$1 [L]
                                               ^^^^^

其中$1是對捕獲的組1的后向引用(這里是關鍵字的值)

試試這個 :

 RewriteCond %{QUERY_STRING} ^keyword=([^&]+) [NC]
RewriteRule ^index\.php$ /catalogsearch/result/?q=%1 [NC,L,R]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM