skip to Main Content

I thought my syntax below would work great to allow IP Ranges using an asterix as the wildcard, but no joy…

Any idea what would work here?

My IP changes the last two batches of numbers….

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteCond %{REMOTE_ADDR} !^112.*.*.*$
#RewriteRule ^(.*)$ - [R=403,L]
RewriteRule ^(.*)$ https://www.example.com/denied.html
</IfModule>

2

Answers


  1. The IP matching regex was incomplete. It was looking for an IP of 112 followed by zero to three dots. That would obviously never happen.

    This would work

    RewriteCond %{REMOTE_ADDR} !^112.
    

    By stripping the last part you would now match any address starting with 112 followed by a dot. This is pretty broad in what it could match. But should be enough for your purpose.

    A more complete version would be this, where you specify the complete address.

    RewriteCond %{REMOTE_ADDR} !^112.d+.d+.d+$
    

    This code snippet should work for you

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} ^(.*)?wp-login.php(.*)$ [OR]
        RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
        RewriteCond %{REMOTE_ADDR} !^112.
        RewriteRule ^(.*)$ https://www.example.com/denied.html
    </IfModule>
    
    Login or Signup to reply.
  2. Could you please try following. Considering that you don’t want to allow any IP starting from 112 then we can keep it simple regex. We need NOT to mention any other digits here since you are not concerned about it.

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^(.*)?wp-login.php(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
    RewriteCond %{REMOTE_ADDR} !^112.
    #RewriteRule ^(.*)$ - [R=403,L]
    RewriteRule ^(.*)$ https://www.example.com/denied.html
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search