Disable / ignore / redirect URLs with query strings to reduce blog spam

TinyApps.Org miles at tinyapps.org
Fri Jul 8 21:29:50 MSD 2011


>>> Is it possible to disable / ignore / redirect all URLs
>>> with any query string? My site doesn't use query strings,
>>> and is suffering from blog spam links
>>> ...

>> server {
>>    if ($args != '') {
>>        return  301  $uri;
> 
> This will not work for complex $uri which requires encoding.
> 
>>        # OR
>>        # rewrite  ^  $uri  permanent; 
> 
> Correct rewrite would be
> 
>          rewrite  ^(.*)  $1?  permanent;
> 
> ($1 instead of $uri to make sure it will be properly escaped, and 
> "?" to avoid query string append).

Thanks so much, Igor & Maxim!

I went with:

  server {
    ... some earlier directives
    if ($args != '') {
    rewrite  ^(.*)  $1?  permanent;
    ... more directives follow
    }

and it works like a charm. Those blog spam links
will be gone in no time! Thank you!!

Sincerely,

Miles






More information about the nginx mailing list