How to block several IPs and show them custom error message?

Discussion in 'Apache' started by postcd, Apr 20, 2016.

  1. #1
    Hello,

    having Apache, PHP webhosting account.
    Can i use .htaccess to block several IPs and show them custom message?

    I mean for example i want to block 3 IPs of company CNN
    1.2.3.4
    2.3.4.5
    6.7.8.9
    and show them message: CNN is not allowed to access this webpage.

    Please which .htaccess rule can i use?
    Or if this is not possible on shared hosting account, what about redirect for this group of IPs, how it would look like?

    thank you
     
    postcd, Apr 20, 2016 IP
  2. TRUE Media Partner

    TRUE Media Partner Member Affiliate Manager

    Messages:
    31
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    33
    #2
    You cant redirect users to custom page with some messages via .htaccess, but you can made custom 403 error-page adding "
    ErrorDocument 403 /dir/file.html" and then "Deny from 1.2.3.4" :)
     
    TRUE Media Partner, Apr 20, 2016 IP
    postcd likes this.
  3. postcd

    postcd Well-Known Member

    Messages:
    1,043
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #3
    Thx, that is a good idea.
    I also found that i can use following:

    note that last IP in the ban list must not have "[OR]" and allowedbyallips.html is a page which will be accessible for all IPs even those i redirect
     
    postcd, Apr 20, 2016 IP
  4. neeshu

    neeshu Well-Known Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #4
    neeshu, Jul 10, 2016 IP
  5. Rob Whisonant

    Rob Whisonant Well-Known Member

    Messages:
    156
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Since you are wanting custom error pages for "different sets" of IPs the best approach would be the rewrite rule you posted above.
     
    Rob Whisonant, Jul 10, 2016 IP