Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: Ocean10000 & incrediBILL & phranque

Query strings being appended to my domain

Spammers adding strange?queires to my domain

   
5:27 pm on Jan 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Heya - So on one of my sites, I keep seeing this: www.domain.com/?q=Insert_Political_Message

I thought the following rewriterule would prevent such things from happening:


RewriteCond %{HTTP_HOST} !^www.example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [QSA,R=301,L]

But apparently not. I didn't think too much of it at the time, but I'm starting to see references to it from google (not in the serps, but in google alerts). Even with a rel=canonical tag it still keeps popping up.

Any ideas how I can prevent this? Has anyone seen anything else similar?

[edited by: jdMorgan at 5:36 am (utc) on Jan. 29, 2010]
[edit reason] example.com [/edit]

10:06 pm on Jan 28, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You need to check the query string value using a RewriteCond, and then redirect to strip it off, fixing the www in the same redirect for those requests. A question mark on the end of the target URL will clear the query string.

There was a thread asking something similar just a few days ago. Check recent posts.

11:18 pm on Jan 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks!

I ended up grabbing the code from this thread:
[webmasterworld.com...]

However the query string remains - What would be the best way to modify this code to get it to include redirecting the query string?

#Fix canoncial issues: http://www.webmasterworld.com/apache/4069463.htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [NC,R=301,L]
#
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com|0\.0\.0\.0)?$
RewriteRule ^ - [F]
#END canonical

[edited by: jdMorgan at 5:29 am (utc) on Jan. 29, 2010]
[edit reason] example.com [/edit]

5:28 am on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



"Grabbing code" without understanding it is asking for trouble... and possibly, really big trouble.

As it turns out, that code isn't relevant to the problem you report. Perhaps the code in this thread [webmasterworld.com] would be more appropriate (read on to the end).

Jim

8:15 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the response! Yes, I'm pretty sure I understood that code for the most part, and based on the discussion in that thread it sounded like it would be applicable to my site as well (with some tweaking) since I run a dedicated ip / server for the site.

But back to the issue at hand - the other thread you referenced was exactly what I was looking for. I tried the code at the end of the thread as well as the apache 2.x code that was posted, however the query string still appears. I'm wondering if maybe I've got something else interfering with it (like wordpress).

I know it's tough to make suggestions without seeing all the code, but any idea what could conflict with such a rewrite rule?

2:17 am on Jan 30, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Most common reasons:
  • Options MultiViews is enabled. If content-negotiation is not used, disable MultiViews.
  • (Apache 2.x and above) AcceptPathInfo is on. If not used, turn it off.
  • The RewriteRule and/or RewriteCond patterns don't match the requested URL-paths (and/or in this case, don't match the query strings)
  • Rule order: Put all of your external redirects first, in order from most-specific (only one or a few URL-paths affected) to least-specific (many URL-paths affected, e.g. domain canonicalization). Then put all of your internal rewrites, again in order from most- to least-specific.
    In general, your domain canonicalization will be your last external redirect rule, and the WP rewrite will be your last internal rewrite. Access-control rules, if any, should precede the external redirect rules.

    You might want to review the recent thread about improving WordPress mod_rewrite code performance [webmasterworld.com].

    Jim

  • 5:42 pm on Feb 1, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Thanks again! I'll have a poke around and see if I Can refine things a bit.
     

    Featured Threads

    Hot Threads This Week

    Hot Threads This Month