Forum Moderators: phranque
Can someone help me and write rewrite rule to prevent this kind of spamming. In such a way that when someone type mydomain.com/?ref=spamsite.com it will redirect to mydomain.com
Thanks
ps
It seems that this rule works:
RewriteCond %{THE_REQUEST} \?(ref=.*)?\ HTTP [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI}? [R=301,L]
[edited by: jdMorgan at 3:50 pm (utc) on Nov. 28, 2009]
[edit reason] example.com [/edit]
RewriteCond %{QUERY_STRING} ref= [NC]
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
RewriteCond %{QUERY_STRING} ref=https?:// [NC]
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
The result is the display of my site with that string added. I tried without success the above mentioned code:
RewriteCond %{QUERY_STRING} ref= [NC]
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
There's probably something I don't understand.
As an aside, in WMT I saw a duplicate description for just one page, one with a trailing slash and one without. Without a trailing slash is the way I want things to be when the URL ends with an extension "/page.html" and I only use a trailing slash for my home page eliminating the "/index.html". Something I'm doing wrong or something I'm missing does allow any page, "/page.html", be returned as "/page.html/" and it just might be what allows the crap I mentioned at the beginning of this post.
The post-slash problem is not related, but if you allow it to happen, then it very well might happen.
Jim
Where mysite is my own site and badsite is the site trying to do this crap.
That takes a different method:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?]*\?cfg\%5bprePath\%5d= [NC]
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
RewriteCond %{QUERY_STRING} ^cfg [NC]
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
Jim
[edited by: jdMorgan at 12:12 pm (utc) on Dec. 1, 2009]
Well, that's the first time there was any indication that the brackets were encoded...
Or that there is an "
/index.html" within the URL path part. Your initial question was for the URL path part...
/?cfg[prePath]=http://www.example.net/01.gif After the solution was given you changed the question to...
/index.html/?cfg%5bprePath%5d=http://www.badsite.net/01.gif All detail for the pattern of the URLs to match is important.
My mistake. For some reason, I was compelled to add the "=" directly after "cfg", which of course didn't match an encoded "[" character...
> I now get "www.example.com/index.php" instead of "www.example.com/".
That indicates that you've got another rule or directive firing before this one, and it is adding "index.php" to the path and that it is subsequently 'exposed' as a URL to the client by the "remove cfg query" redirect.
My guess would be an internal rewrite that may also be missing the generally-recommended [L] flag.
All external redirect rules must precede any internal rewrite rules, and both of these redirect and rewrite rule groups should be ordered from most-specific patterns and conditions to least-specific.
Jim