Forum Moderators: phranque

Message Too Old, No Replies

Redirecting URLs with a "?" in them

Taking care of leeches who link to my site with a? and their domain

         

Stefan

12:14 am on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could any of you .htaccess geniuses tell me why this doesn't work?

redirect 301 /example.htm?leech.com h*tp://www.domain.org/example.htm

I've had a "directory" link to my pages recently that's using the? method, and the URL's are returning 200's. No harm yet in the serps, but it's dupe content.

Many thanks to anyone who can be of help on this - maybe that redirect isn't the way to go? Can I do it with mod rewrite?

[edited by: jdMorgan at 5:55 am (utc) on May 7, 2006]

jdMorgan

6:01 am on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not part of a URL, but rather, data attached to a URL to be passed to the resource *at* that URL. They are therefore handled separately in Apache.

In mod_rewrite:


RewriteCond %{QUERY_STRING} ^http://(leech\.com¦dummy\.com) [NC]
RewriteRule ^example\.htm$ http://example.com/example.htm? [R=301,L]

Replace all broken pipe "¦" characters above with solid pipes before use; Posting on tis forum modifies that character.

Jim

Stefan

11:45 am on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey, many thanks, Jim. I'll get on it as soon as I've finished my first cup of coffee (still waking up right now).

Stefan

1:29 am on May 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's doing the trick. I changed it to:

RewriteCond %{QUERY_STRING} ^(leech\.com) [NC]
RewriteRule ^mypage\.htm$ h*tp://www.mysite.org/mypage.htm? [R=301,L]

The leech site didn't have an http:// at the front. The ¦ is just to add other leech sites is it?

Is it possible to do it site-wide, for anything that comes in with the query string? I've started reading up on htaccess and query strings (I've read of query strings here, but didn't realize they were the url's with the "question mark" - I never use the things), so might eventually figure it out myself. Great start anyway.

Added: I have over 400 pages, and that "directory" has so far only linked to one page, but if they link to a lot of others, it's many entries in my htaccess if I have to do it one at a time. Because I don't use query strings, I figure it should be possible to change /anypage.htm?leech.com to /anypage.htm