Forum Moderators: phranque

Message Too Old, No Replies

Redirecting to same place

         

aorta

4:27 am on Sep 19, 2012 (gmt 0)

10+ Year Member



Hi,
I have a Wordpress site and at one time I installed a mobile plugin. I disabled and removed it, but it left traces in my site.
When I look at Webmaster tools I have duplicate content from this plugin. it leaves duplicate urls that look like this;
http://example.com/testing wpmp_switcher=mobile
or wpmp_switcher=destop

there are a few more. I have added the following rewrite to redirect to the original article.


RewriteEngine on

RewriteCond %{query_string} ^wpmp_switcher=mobile [OR]
RewriteCond %{query_string} ^wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=0 [OR]
RewriteCond %{query_string} ^wpmp_tp=1 [OR]
RewriteCond %{query_string} ^wpmp_tp=2 [OR]
RewriteCond %{query_string} ^wpmp_switcher=mobile&wpmp_tp=0 [OR]
RewriteCond %{query_string} ^wpmp_switcher=mobile&wpmp_tp=1 [OR]
RewriteCond %{query_string} ^wpmp_tp=1&wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=1&wpmp_switcher=mobile [OR]
RewriteCond %{query_string} ^wpmp_tp=0&wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=0&wpmp_switcher=mobile
RewriteRule (.*) /$1 [R=301,L]


These are always duplicates of an original article, so http://example.com/index.html becomes http://example.com/index.html wpmp_switcher-mobile

This does a good job, but it redirects to the same url with the wpmp_switcher-mobile. It does redirect, but to the exact same url.
Does anyone know what is wrong with the above and how to fix it?

Thank You

[edited by: incrediBILL at 2:43 am (utc) on Sep 20, 2012]
[edit reason] use exmple.com [/edit]

g1smd

6:12 am on Sep 19, 2012 (gmt 0)

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



Add protocol and hostname to the target URL.

Add a trailing question mark to suppress parameters on the target.

Use example.com in this forum to suppress URL auto-linking.

phranque

8:08 am on Sep 19, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, aorta!

what g1smd said:

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_r
Use of the [R] flag causes a HTTP redirect to be issued to the browser. If a fully-qualified URL is specified (that is, including [servername...] then a redirect will be issued to that location. Otherwise, the current protocol, servername, and port number will be used to generate the URL sent with the redirect.

(you specify protocol and hostname to avoid redirecting to a non-canonical protocol and hostname if requested.)

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
Modifying the Query String-
... When you want to erase an existing query string, end the substitution string with just a question mark. ...


IMPORTANT: Please Use Example.com For Domain Names in Posts - Apache Web Server forum at WebmasterWorld:
http://www.webmasterworld.com/apache/4452736.htm [webmasterworld.com]

lucy24

9:15 am on Sep 19, 2012 (gmt 0)

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



As others have already said, the problem with your htaccess is that the server is doing exactly what you've told it to do. No more and no less.

Now, once you get the important stuff figured out, you should spend some more time with
RewriteCond %{query_string} ^wpmp_switcher=mobile [OR]
RewriteCond %{query_string} ^wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=0 [OR]
RewriteCond %{query_string} ^wpmp_tp=1 [OR]
RewriteCond %{query_string} ^wpmp_tp=2 [OR]
RewriteCond %{query_string} ^wpmp_switcher=mobile&wpmp_tp=0 [OR]
RewriteCond %{query_string} ^wpmp_switcher=mobile&wpmp_tp=1 [OR]
RewriteCond %{query_string} ^wpmp_tp=1&wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=1&wpmp_switcher=mobile [OR]
RewriteCond %{query_string} ^wpmp_tp=0&wpmp_switcher=desktop [OR]
RewriteCond %{query_string} ^wpmp_tp=0&wpmp_switcher=mobile

That's an awfully long list of similar conditions. Some are already redundant. It should be possible to collapse them into a much shorter list by (probably) leaving off some opening anchors anchors and (definitely) doing some business with parentheses and pipes.

Are there any configurations of "wpmp_switcher" and "wpmp_tp" that don't need to be redirected? You may even be able to change to a "Not A and Not B" format instead of the present "A or B or C or D or..."

g1smd

9:26 am on Sep 19, 2012 (gmt 0)

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



Certainly the last four conditions condense into one if you use [01] and (desktop|mobile) in the replacement condition.

Near the beginning, using [012] sees another simplification and [01] in the next set.

aorta

1:00 pm on Sep 19, 2012 (gmt 0)

10+ Year Member



Thanks for the replies. Im afraid you are way over my head here. Can you post a rewrite that would work? I want to redirect to the same url, without the references to wpmp.
thanks

g1smd

1:36 pm on Sep 19, 2012 (gmt 0)

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



blah=0 [OR]
blah=1

simplifies to

blah=[01]

and so on.

lucy24

8:03 pm on Sep 19, 2012 (gmt 0)

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



Your RewriteConds all involve the same two queries:

wpmp_tp (with possible values 0, 1, 2)
and
wpmp_switcher (with possible values "mobile", "desktop")

#1 Can either of these queries yield other values that you need to retain?
#2 Are there other possible additional queries that you need to retain?

If these two are the only queries you ever use, and they have no other values, then everything reduces to the single unanchored line

RewriteCond %{QUERY_STRING} wmtp_(tp|switcher)

and the RewriteRule simply ends in ? to whack off the entire query string.

But if either #1 or #2 above has "yes" answer then you need to go into more detail. Second-easiest scenario: one or the other query may occur in combination with others that you need to keep-- but these two always come first. I think you could still pack it into a single

RewriteCond %{QUERY_STRING} ^(?:wmtp_tp=[012]|wmtp_switcher=\w+)*(&.+)?

with a RewriteRule ending in ?%1

This builds on the fact that Regular Expressions are greedy by nature and will grab as much as they can unless you specify that there must be something left over. The ?: makes the first group non-capturing so you don't have to keep track of it later.