Saltar al contenido

~ / archivo / stackoverflow / 50334656

Using "deny from {IP}" with 410 response (instead of 403) for selected IPs

StackOverflow · apache, .htaccess · ayudé
  1. Tomasz pregunta +1 2018-05-14 16:06

    Currently when I want to block an IP in .htaccess, I use:

    deny from 192.168.1.1
    

    It produces 403 (Access Denied) response.

    My question is - would it be possible to have 410 response instead of 403? Ie. would this be proper to use?

    deny from 192.168.1.1 [G,L]
    

    (G - gone = 401 response), (L - last execution, don't look any further)

    I found some idea here - HTACCESS / ErrorDocument - How to serve 410 instead of 403 but it covers all denied IPs; here, I'd like to use 410 response only for selected IPs (that's why I was hoping that adding [G,L] by them would make sense and be the easiest solution, if it's proper..

  2. Miguel Ortiz yo respuesta +1 2018-05-14 17:56

    I would suggest redirecting, which lead to the desired error code:

    RewriteCond %{REMOTE_ADDR} 1.2.3.4
    RewriteRule .* /CustomError.html [R=410]
    

    But you also could make that 403 present an HTML saying it's a 410 error:

    <Location /server-status>
        SetHandler server-status
        Order Allow,Deny
        Deny from  all
        Allow from 192.168.16.0/24
        ErrorDocument 403 /dir/test.html
    </Location>
    

    And in test.html just write:

    <p>Error 410</p>
    

← todos los hilos de StackOverflow