.htaccessblockingapache2.4

about blocking a country by using .htaccess


I have tried many times, I feel desperate. I have been able to do this successfully before on Apache 2.2. Now my environment is Apache/2.4.18 (Ubuntu) Server

I go to https://www.ip2location.com/blockvisitorsbycountry.aspx to generate code

  1. select ipv4
  2. select China
  3. select "Apache 2.4 .htaccess deny"

Then add the code to the bottom of .htaccess.

However, the result is that I cannot access the website whether I use a VPN or not.

I am located in China.

Later, I tried to select another one country, such as Japan, to generate new blocking code.

However, the result was the same, after adding the code into .htaccess. I also cannot access the website, even though the blocked country is Japan and I am in China.

I doubt the code, what should I do in order to get the right blocking a country code?


Some of the generated code:

<RequireAll>
Require all granted
Require not ip 1.0.1.0/24
Require not ip 1.0.2.0/23
Require not ip 1.0.8.0/21
Require not ip 1.0.32.0/19
Require not ip 1.1.0.0/24
Require not ip 1.1.2.0/23
Require not ip 1.1.4.0/22
:

Solution

  • now,I have solved the problem.

    first of all, the code generated from https://www.ip2location.com/blockvisitorsbycountry.aspx is 100% correct!

    the reason why I cannot access the website whether using VPN or not,is that I didnot add the following code to yourdomain.conf to make https(ssl) url also support rewrite.

        <VirtualHost *:443>
        .......
    
       <Directory "/var/www/html/yourdomainname/public_html">
           AllowOverride All
           Require all granted
       </Directory>
        </VirtualHost>