0

How using mod_rewrite could i manipulate the query string variable?

e.g. i want the following query string:

?route=product​/product&​product_id=158?​ax13g76h

rewritten to:

?route=product​/product&​product_id=158

Basically i only want to keep everything between the 2 question marks. As soon as the second question mark is hit everything after is removed

Is this possible?

1 Answer 1

3

For this case you can use this:

RewriteCond %{QUERY_STRING} route=product/product&product_id=(\d+).*
RewriteRule (.*) $1?route=product/product&product_id=%1

And for all other

RewriteCond %{QUERY_STRING} (.+)\?.*
RewriteRule (.*) /$1?%1 [L,R=301]
Sign up to request clarification or add additional context in comments.

6 Comments

hmmmm this actually did nothing
This didn't change url. This modify query string. You can print $_REQUEST array and see difference
so how do i change the url as well?
Do you enable RewriteEngine (RewriteEngine On) ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.