mod_rewrite rule to drop the string with m=1 from the URL regardless of its location?

56 Views Asked by At

How to create a mod_rewrite rule that can change this:

exampledomain/blog/2013/10/?view=flipcard&m=1&_escaped_fragment_=

To this:

exampledomain/blog/2013/10/

And this:

exampledomain/blog/review-of-items/?view=timeslide&m=1

To this:

exampledomain/blog/review-of-items/

Basically to check inside the final string for m=1 and drop that final string only regardless of the number of slashes beforehand?

And please note we are not dropping m=1 only like in some other questions, we would like to get rid of the entire string i.e. ?view=flipcard&m=1&_escaped_fragment_= or ?view=timeslide&m=1

1

There are 1 best solutions below

2
On BEST ANSWER

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)m=1(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=302]

(^|&)m=1(&|$) regex is to make sure m=1 is matched anywhere in query string.