0

Can someone help me make this functional?

The goal is to provide a list of blacklisted paths ({REQUEST_URI}) and a list of whitelisted IPs ({REMOTE_ADDR}) and block accordingly. Currently the below code works if only the first {REQUEST_URI} is defined but the addition of [OR] and more {REQUEST_URI} lines breaks it.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase / 

# ======= IF YOU WANT TRY TO REACH ANY OF THESE... =======
RewriteCond %{REQUEST_URI} ^/wp-admin.* [OR]
RewriteCond %{REQUEST_URI} ^/wp-login.php [OR]
RewriteCond %{REQUEST_URI} ^/wp-content/readme.txt


# ======= AND YOU'RE NOT AT ONE OF THESE IP ADDRESSES... =======
#
# ===== OFFICE ===== 
#RewriteCond %{REMOTE_ADDR} !^XX\.XX\.XX\.XXX [NC]
# ===== HOME ===== 
#RewriteCond %{REMOTE_ADDR} !^XX\.XX\.XX\.XXX [NC]

# ======= THEN YOU'RE FORBIDDEN AND ARE SERVED AN ERROR PAGE TELLING YOU SO =======
RewriteRule ^.*$ - [L,F]
ErrorDocument 403 https://youtu.be/cQ_b4_lw0Gg
</IfModule>
1
  • The code you've posted looks like it should "work" providing the last 2 conditions are uncommented and this code block is all before the WordPress front-controller. (The NC flag is not required on the IP conditions.)
    – MrWhite
    Feb 27, 2020 at 20:40

1 Answer 1

1

(The NC flag is not required on the IP conditions.) – MrWhite

Thanks. Removed. I found the solution. This works as desired:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase / 

# ======= IF YOU WANT TRY TO REACH ANY OF THESE... =======
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$ [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin.* [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?readme\.html(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?readme\.txt(.*)$

# ======= AND YOU'RE NOT AT ONE OF THESE IP ADDRESSES... =======
#
# ===== OFFICE ===== 
#RewriteCond %{REMOTE_ADDR} !^XX\.XX\.XX\.XXX
# ===== HOME ===== 
#RewriteCond %{REMOTE_ADDR} !^XX\.XX\.XX\.XXX

# ======= THEN YOU'RE FORBIDDEN AND ARE SERVED AN ERROR PAGE TELLING YOU SO =======
RewriteRule ^.*$ - [L,F]
ErrorDocument 403 https://youtu.be/cQ_b4_lw0Gg
</IfModule>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .