Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:47:58+00:00 2026-06-13T09:47:58+00:00

I read and understand how to block an ip using htaccess: order deny,allow deny

  • 0

I read and understand how to block an ip using htaccess:

order deny,allow
deny from 111.222.33.44
deny from 55.66.77.88
...
allow from all

But my list of black IPs includes thousands of IPs.
I save all IPs to a blacklist.txt file.

Can I use htaccess to call blacklist.txt and block all IPs which are stored in this file? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:47:59+00:00Added an answer on June 13, 2026 at 9:47 am

    You can try using variations of RewriteMap. You’ll need access to the server/vhost config because that directive only works there. You can then use the map inside htaccess files.

    Say your blacklist.txt file looks like this:

    111.222.33.44  deny
    55.66.77.88    deny
    192.168.0.1    allow
    

    You can define the map like so:

    RewriteEngine On
    RewriteMap access txt:/path/to/blacklist.txt
    

    Then in your htaccess, you can invoke the map:

    RewriteEngine On 
    RewriteCond ${access:%{REMOTE_ADDR}} deny [NC]
    RewriteRule ^ - [L,F]
    

    The condition invokes the map and checks if the remote address maps to the word “deny”, and if so, the rewrite rule outright forbids access.

    If your blacklist.txt is only a list of IPs, and you don’t want to add a “deny” after each one, you’ll need to invoke a program map type and write a script, something like this:

    #!/bin/bash
    
    while true
    do
        read INPUT
        MATCH=`grep $INPUT /path/to/blacklist.txt`
        if [ -z "$MATCH"  ]; then
            echo "allow"
        else
            echo "deny"
        fi
    done
    

    which infinite loops read input and greps the blacklist.txt file. If the IP is in the file, output a “deny”, otherwise it outputs a “allow”. Then you’d create the map like so:

    RewriteEngine On
    RewriteMap access prg:/path/to/blacklist.txt
    

    And the rewrite rule to check against the map would be no different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read and I believe I understand what C#'s using statement does (please correct
I understand that one of the advantages of using stdio.h FILE over direct read()
I searched a variety of sources but don't really understand the difference between using
I'm using ioctl() to check if the read-end of a pipe would block. I
I have the following block of code that i am using to read a
I cannot understand why a call to read after an lseek returns 0 number
I read so many blogs and I understand how to use virtual function in
I read the answers to this question and understand what the code var qq
I read various stuff on this and understand the principle and concepts involved, however,
I read Windows Azure Toolkit for Android to understand how I can connect Android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.