HTACCESS Denying bad requests

Discussion in 'Apache' started by RectangleMan, May 13, 2010.

  1. #1
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?4834 HTTP/1.1" 503 2199 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?4987 HTTP/1.1" 503 2199 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:26 -0700] "POST / ?4886 HTTP/1.1" 503 2199 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?5036 HTTP/1.1" 503 2199 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?4935 HTTP/1.1" 200 0 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?5549 HTTP/1.1" 200 0 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
    e.net.log:99.99.999.999 - - [13/May/2010:19:19:27 -0700] "POST / ?5190 HTTP/1.1" 200 0 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"

    that's example logs. As you can see this will produce a bad header request and ther is no url "/?5190"


    So it's a POST to a nonexistent URL. I'd like to make an htaccess directive to deny these as there are thousands that hit my server. I'm terrible with regex. I'd like some assistance if possible.
     
    RectangleMan, May 13, 2010 IP
  2. RAmoss

    RAmoss Guest

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^?[0-9]{4}$ [NC]
    RewriteRule .* - [F,L]
    </ifModule>
     
    RAmoss, May 17, 2010 IP
  3. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Yeah I finally got it about 20 minutes after posting this but thanks for posting. Hopefully it will help the next guy.

    I actually used this:

    RewriteCond %{QUERY_STRING} ^([0-9]+)$
    RewriteRule .* - [F]


    That will do any number of digits.
     
    RectangleMan, May 17, 2010 IP