homepage Welcome to WebmasterWorld Guest from 54.226.93.128
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess redirect
Gemini23




msg:4662771
 12:09 am on Apr 14, 2014 (gmt 0)

I have a Wordpress problem.. in that a previously installed/removed mobile plugin has generated a number of character extensions to urls... such as (I believe two of these were made by the plugin and not sure about teh other two...)

?newwindow=true
?wpmp_tp=1
?wpmp_switcher=desktop
?wpmp_switcher=mobile

Basically I have a number of urls that have been generated with those character strings after the correct url...

what I would like is a redirect in the htaccess to redirect to the root of the original url...

I believe this may be correct... but a) is it correct? and b) how to I add all of the variables to it?

## Strip Mobile Pack query strings ##

RewriteEngine on

RewriteCond %{QUERY_STRING} ^wpmp_.* [NC,OR]

RewriteCond %{QUERY_STRING} (.+)&?wpmp_.*$ [NC]

RewriteRule ^(.*)$ $1?%1 [R=301,L]

## END of Strip Mobile Pack query strings ##

 

lucy24




msg:4662776
 2:10 am on Apr 14, 2014 (gmt 0)

Last things first:
RewriteRule ^(.*)$

Can you constrain this rule more tightly? How many places do you see the unwanted queries? They don't attach themselves to image requests, do they? The idea is to keep the server from having to detour and evaluate a condition on every single request.

Next question: When these unwanted queries occur, are they
-- the only query string in the visible URL
-- always the last or first part of a longer query string
-- or can they occur absolutely anywhere?

Also: Do the unwanted bits ever occur in the same URL, or is it always just one or the other? I see that three of them involve "wpmp_[a-z]+". Is there ever more than one in this pattern?


?newwindow=true

This one is personally interesting to me, because a while back it showed up in my parameters list in wmt. Not only do I not use this (or any other) parameter, I don't use WP! I assumed they were simply misreading a link from someone else's site.


Your rules as shown are a bit scruffy-looking and can definitely be fine-tuned. Whether they are out-and-out wrong depends on your exact URL structure. The %1 element in the target implies that there may be queries you want to preserve, and that they may come before the unwanted stuff. I wouldn't do this with an OR condition. In fact I'm not sure it would work at all, and this is no place for trial and error.

:: poring over rule ::

I think I see what you're trying to do. But before anything else, see whether the "wpmp_" business actually occurs both initially and non-initially. No point in making rules for problems that will never happen in real life. What about the stuff that comes after it? The rule looks as if the rest of the query, if any, is simply discarded.

Gemini23




msg:4662845
 9:25 am on Apr 14, 2014 (gmt 0)

Thanks for the detailed reply... without exception the above all appear at the end of the correct url... and display the contents of the correct url...

lucy24




msg:4662923
 4:22 pm on Apr 14, 2014 (gmt 0)

and display the contents of the correct url...

It would be a lot more worrying if the extraneous parameters did affect page content!

One thing you can do is go into the "parameters" area of webmaster tools in any search engine that has the option. See if the unwanted parameters are listed; if they are, check the box for "doesn't affect page content".

So what you want is something like

RewriteCond %{QUERY_STRING} ^(([^&]+&)*)wpmp_
RewriteRule (blahblah) http://www.example.com/$1?%1 [R=301]

except that it may be easier on your server to go two steps forward and one step back, as in
RewriteCond %{QUERY_STRING} wpmp_
RewriteCond %{QUERY_STRING} ^(([^&]+&)*)wpmp_

What this says is "don't waste your time capturing and fine-tooth-combing unless we've already established that the target element actually does occur in the query". The second condition will, of course, always succeed; its sole purpose is to create a capture. You've said that the offending parameter always comes last, and that's a help. If it turns out you're mistaken, the Condition becomes a tiny bit more complicated and you end up with %1%2. But let's not borrow trouble.

Now, about that blahblah. What do your page URLs look like? php, extensionless, slash? The issue is that any given page request will contain one page file and then any number of non-page files. Since the rule involves looking at conditions, you want to set it up so the server can bypass this step when it already knows that the condition will fail. So something like

RewriteRule ^([^.]+(\.php|/))?$ et cetera

but the details will depend on your site. Here too it may be faster in the long run to go two steps forward and one steps back, as in

RewriteCond %{QUERY_STRING} wpmp_
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^&\ ]+&)*)wpmp_
RewriteRule (/|\.php|^)$ http://www.example.com/%1 [R=301,L]

doing all the capturing in one fell swoop. That version looks goofy but I'm pretty sure it's correct. At least more correct than it would have been at 2:30 AM when I first saw the question.

Gemini23




msg:4662955
 7:23 pm on Apr 14, 2014 (gmt 0)

THAt is exactly what I had a look at this afternoon...

One thing you can do is go into the "parameters" area of webmaster tools in any search engine that has the option. See if the unwanted parameters are listed; if they are, check the box for "doesn't affect page content".

not2easy




msg:4662966
 7:48 pm on Apr 14, 2014 (gmt 0)

Have you also looked at the settings you have in place for URLs? Did this plugin make changes to your settings? Are you using other plugins that alter URL structure?

Gemini23




msg:4662978
 8:55 pm on Apr 14, 2014 (gmt 0)

I believe it was a Wordpress Mobile plugin that - having read many other posts about it - causes a lot of urls such as ?wpmp_switcher=desktop
?wpmp_switcher=mobile
that Google indexes... it will show 3 urls with the same content... I am not sure whether anyone has been penalised by Google for that...

lucy24




msg:4662981
 9:17 pm on Apr 14, 2014 (gmt 0)

Same content or same appearance? Turns out-- I just learned this recently-- that when they talk about a parameter affecting page content, they don't mean the same thing that they mean when they refer to "duplicate content". Instead, "affects page content" includes things like sort order, where the identical material is simply displayed in a different way.

So if the different values of "wpmp_blahblah" make the page look different even while it shows the identical words, you proceed to the next wmt option: "Yes it affects page content, but please only crawl one representative URL".

If the parameter has no effect at all, you can tell the search engine to ignore it. But you should also redirect, because why bother to keep something in your URL that doesn't do anything?

:: idly wondering why this was ever part of the URL, when the same information is better handled with cookies ::

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved