Rewrite the query string to another query string

I need to take the search URLs that are submitted to my site as follows:

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

and change them to:

 /catalogsearch/result/?q=47174

I need to take a value after "keyword =" ignores everything after the "and" sign and passes it to the second URL after "q =

This is what I came up with so far:

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

This, however, prints the keyword = at the end of the URL, does not print q =, or clears everything after &

How can i fix this?

+4
source share
3 answers

Try the following:

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

You want your RewriteRule to have something like:

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

Everything inside the brackets will replace %1on the right side.

+1
source

:

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

$1 - 1 (.. )

+1

Source: https://habr.com/ru/post/1589526/


All Articles