Mobile app version of vmapp.org
Login or Join
Gonzalez347

: 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

@Gonzalez347

Posted in: #Htaccess #ModRewrite

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|d‌​evices|shops)?$ index.php?route=module/ecomapi/ [B,L,QSA]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gonzalez347

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme