Forum Moderators: phranque

Message Too Old, No Replies

Update: Strip Mobile Query String

WordPress Redirect Mobile Query String

         

2011R2d2

9:15 pm on Feb 29, 2012 (gmt 0)

10+ Year Member



I don't give up easily and so, when I found the perfect solution tonight, 5 months down the line, I wish to enlighten all as to the solution I found relating to the post I made in September "Strip Query String - too many redirects for WordPress" on thread: [webmasterworld.com...]

All the advice I got before on the forum, however much appreciated, didn't work but THIS did...


## Strip Mobile Pack query strings ##
RewriteCond %{QUERY_STRING} ^wpmp_.* [NC,OR]
RewriteCond %{QUERY_STRING} (.+)&?wpmp_.*$ [NC]
RewriteRule ^(.*)$ $1?%1 [R=301,L]

## Strip Mobile Pack query strings ##
RewriteCond %{QUERY_STRING} ^mobile_.* [NC,OR]
RewriteCond %{QUERY_STRING} (.+)&?mobile_.*$ [NC]
RewriteRule ^(.*)$ $1?%1 [R=301,L]

g1smd

9:27 pm on Feb 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The trailing
.*$
and
.*
are all redundant.

You should add the protocol and hostname to the rule target.

The leading
(.+)
part is greedy, ambiguous and promiscuous. It slows the parser considerably.

lucy24

10:49 pm on Feb 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, that's interesting on a different count. Something in another thread made me wonder if a null capture (not the same as an empty one) would make the server throw fits. Apparently not, since your paired Conditions mean that %1 may or may not exist at all.

So the Rules say: If the query string contains something before "wpmp_" or something before "mobile_" then capture and reuse that part only? Are they mutually exclusive? That is, a query string can contain either "wpmp_" or "mobile_", but not both? If so, you can probably consolidate them into a single group of Conditions feeding into a single Rule.

2011R2d2

5:30 pm on Mar 23, 2012 (gmt 0)

10+ Year Member



@g1smd

I have changed the + to *

It's been 6 months of never giving up to find a solution that works.
Whether anything is redundant, of a particular protocol...or any of the rest you mention, I pretty much don't have the energy to go into it unless I get clear guidance.

@lucy24

Exactly!
Mutually exclusive... Not exactly. Two separate mobile plugins left this mess for me. One used some coding of the other, so apart from the single instances, I also had to deal with:

There are
=mobile
=desktop

...and any other permutation you can think of in between PLUS...

http://www.example.com/this-is-the-post/?wpmp_switcher=mobile&mobile_switch=desktop

Mortifying, I know!

mslina2002

2:59 am on Mar 24, 2012 (gmt 0)

10+ Year Member



It's been 6 months of never giving up to find a solution that works.


So has the problem gone away with the redirect?

I saw these queries showing up also but in WMT I specified to ignore the parameters and the problems went away. Did not use any .htaccess redirect for that.