1

Trying to achieve

Source -

https://rrr.rrr.com/us/Product-Family/Products/c/Products/layout?layoutType=false&page=0&grid=true&q=:relevance:DriveType:Flash:ProductFamily:Prd 1

To

 https://rrr.rrr.com/us/Product-Family/Products/c/Products/layout?layoutType=false&page=0&grid=true&q=:relevance:DriveType:Flash SSD:ProductFamily:Prd 1

trying to find and replace DriveType:Flash to DriveType:Flash SSD anywhere in Query String

Problem is that DriveType:Flash SSD can appear anywhere in the Query String

  • Literally anywhere in the query string? Or anywhere within the q parameter value of the query string (as in your example)? – MrWhite Sep 15 '14 at 16:18
1

Try the following in .htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)DriveType:Flash:(.*)$
RewriteRule ^us/Product-Family/Products/c/Products/layout$ /$0?%1DriveType:Flash SSD:%2 [R=301,L]

This only matches the URL specified and externally redirects to the new URL. This could perhaps be made more efficient by restricting the pattern that will match before and after the required string. At the moment .* matches anything (and nothing).

In the RewriteRule substitution: $0 is the entire string/URL matched by the RewriteRule pattern and %1 and %2 are the corresponding sub patterns in RewriteCond matched before and after the required string to replace.

Note that I've included the : at the end of the pattern to avoid a rewrite loop. If the pattern does not always end with a : then this will need to be changed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.