Forum Moderators: phranque

Message Too Old, No Replies

Query strings google issue

         

dodge2010

9:27 am on Nov 20, 2010 (gmt 0)

10+ Year Member



Hi,

Hope someone can help me with this its driving me crazy.

My domain has issues with links to it which google is treating as duplicate pages in my goole webmaster panel.

Example:

mydomain.com?td=anotherdomain.com
mydomian.com?x=6766.7445.9867.5566
mydomain.com?tid=domainname

and many different combination of the above.

Is there anyway to 301 redirect any link coming into the domain with a "?" Query after the actual domain name to my main home page via htaccess?

But leaving any other page untouched, ie mydomain.com/page.php?item1=40 would be left alone.

Any pointers would be greatly appreciated.

Thank you.

g1smd

10:25 am on Nov 20, 2010 (gmt 0)

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



Yes, and it's a topic that's been discussed many times before.

Use a RewriteCond to detect the presence of a QUERY_STRING.

Use a RewriteRule to do the redirect, The target URL will need to specify the protocol and domain name. Append a question mark to the target URL to clear the query string value. Add the [R=301,L] flags.

Check prior threads for detailed discussion and code examples.

Don't redirect all requests to the home page; instead strip the query string and redirect to the page that was requested.

dodge2010

10:46 am on Nov 20, 2010 (gmt 0)

10+ Year Member



Hi g1smd,

Thanks for the reply, Ive been trwaling this section for hours and although i can find many pages that kind of resemble the issue i`m having i can not make head nor tail of any of the code (htaccess is a mistery to me)

Also as far as the redirect to the home page is concerned all the example urls and many more mentioned actually do point to the same page (the index page) but google is treating each one as a different page with exactly the same ontent.

Would this work?

RewriteCond %(QUERY_STRING) ^domainname.com?(.*)$
RewriteRule .* /domainname.com [L,R=301]

thank you for your help.

g1smd

2:22 pm on Nov 20, 2010 (gmt 0)

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



QUERY_STRING contains only the query string, or blank. A "dot" as the RegEx pattern will match if anything is present at all for query string.

The RewriteRule target should contain the protocol and domain name. Append a question mark to the target URL to clear the query string value.

Your current ruleset will only work for a request like:
www.example.com/<anything>?domainname.co<anything>

and will redirect to:
www.example.com/domainname.com

dodge2010

4:28 pm on Nov 20, 2010 (gmt 0)

10+ Year Member



So would this work...

RewriteCond %(QUERY_STRING) ^domainname\.com(?*)$
RewriteRule .* /index.php [L,R=301]

With the result im looking for is anything with a "?" after the domain name being redirected to index.php (which is the main home page)

does seem to be throwing up error but its quite hard to do on a live site.

Thanks again

Mark

dodge2010

1:08 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Oh my god this is so frustrating ive spent all day yesterday and half of today searching and trying different ways but still nothing.. should be so simple but i just cant see where its going wrong.

I cant even seem to get a simple directory to redirect, Im using:

redirectmatch 301 /cgi-bin/FOLDER/.*http://www.DOMAIN.com?

Which does redirect to the home page fine as desired however i put the "?" on the end of the domain to stop any arguments being appended to it... but now i get the domain with the "?" on the end.

If anyone could help me with this and especially the main problem above i would be so grateful!

Thank you.

dodge2010

4:57 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Woo hoo second problem solved and first one getting close to solve hopefully :)

The problem:
I have lots of links coming into site such as:

mydomain.com?td=anotherdomain.com
mydomian.com?x=6766.7445.9867.5566
mydomain.com?tid=domainname

and many different combination of the above, which is causeing google to flag up as duplicate content etc.

What i`m trying to do is 301 redirect to my main home page any thing that comes in with a "domain.com?anything" argument.
However what i have now does achieve this but also strips any "?" arguments on other pages on the site that i do need to use.

I now have:

Options +FollowSymLinks
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) [domain.com...] [R=301]


Any ideas?

Thank you.

g1smd

8:58 pm on Nov 21, 2010 (gmt 0)

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



For the RewriteCond, QUERY_STRING contains only the query string, or blank. It does not contain the domain name. It does not contain the URL path. A "dot" as the RegEx pattern will match if anything is present at all for query string.

The RewriteRule target should contain the protocol and domain name. Append a question mark to the target URL to clear the query string value.

Your original question asked to redirect for all requests with query strings. To allow for some to not be redirected, you'll need a preceding negative match RewriteCond which "white lists" all parameter names that are valid.

dodge2010

9:19 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Hey g1smd,

I think ive got it... This works for me:
It redirects all querys starting with "t" or "x" to the home page which is good enough for me.

But am i likely to see any other strange effects i had not planned on from this code?

RewriteCond %{QUERY_STRING} ^t [OR]
RewriteCond %{QUERY_STRING} ^x
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

thanks for the tips buddy.

g1smd

7:40 am on Nov 22, 2010 (gmt 0)

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



Make the target
http://www.example.com/$1?
here.

The
$1
preserves the originally requested page, while the question mark strips the parameters.

It is bad form to redirect to the root.

dodge2010

10:48 am on Nov 22, 2010 (gmt 0)

10+ Year Member



hey,

The original requested page was the root/index of the site.

mydomain.com?td=anotherdomain.com
mydomian.com?x=6766.7445.9867.5566
mydomain.com?tid=domainname

are all referers to the site that use those ? arguments to track track, however they are not needed for me to track them coming in... they are all from an old script a stopped using over a year ago.

However for some reason google has them all down as identical disciption and title tags for my site for some reason.

Hence directing them all with a 301 hopefully they will appear as the same page (which they are).

Any thoughts on that?

Thanks again

jdMorgan

7:31 pm on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can shorten your code, and make it more specific to avoid unexpected redirects:

RewriteCond %{QUERY_STRING} ^[tx]
RewriteRule ^$ http://www.example.com/? [R=301,L]

Jim