: Mod_rewrite part of the query string I have a situation with opencart where I need to rewrite only the "route" leaving other query strings as it is. Example: http://www.example.com/?route=module/ext/products&category_id=15
I have a situation with opencart where I need to rewrite only the "route" leaving other query strings as it is. Example:
www.example.com/?route=module/ext/products&category_id=15&sort=newest
to
www.example.com/ext/products?category_id=15&sort=newest
how can I do that?
UPDATE: I have some constraints. This rewrite condition should only be applied to route=module/ecomapi/([^&]+). Not for other routes.
RewriteRule ^ecomapi/21/(products)/([^?]*)$ index.php?route=module/ecomapi/&product_id= [L]
RewriteRule ^ecomapi/21/(login)/([^?]*)$ index.php?route=module/ecomapi/&email= [L]
RewriteRule ^ecomapi/21/(users)/([^?]*)$ index.php?route=module/ecomapi/&id= [L]
RewriteRule ^ecomapi/21/(products|navigation_drawer|banners|cart|login|devices|shops)?$ index.php?route=module/ecomapi/ [B,L,QSA]
More posts by @Gonzalez347
1 Comments
Sorted by latest first Latest Oldest Best
Try the following near the top of your .htaccess file (or server config):
RewriteEngine On
RewriteCond %{QUERY_STRING} ^route=module/([^&]+)&?(.*)$
RewriteRule ^/?$ /%1?%2 [R,L]
This makes the following assumptions:
An external redirect (302 - temporary). (Change the R flag to R=301 to make it permanent.)
Only an initial request for the document root is considered.
The route URL param always exists at the start of the query string.
Everything after module/ in the route URL param value is extracted to form the URL-path in the substitution.
There must be something after module/. But this "something" could be anything. (You should probably be as explicit as possible here in order to prevent matching against wholly invalid URL-paths.)
The route URL parameter could be the only URL param.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.