有人能帮助我实现这个功能吗?
目标是提供黑名单路径列表 ( {REQUEST_URI}
) 和白名单 IP 列表 ( {REMOTE_ADDR}
) 并进行相应的阻止。目前,如果仅定义了第一个,则以下代码可以正常工作,{REQUEST_URI}
但添加[OR]
更多{REQUEST_URI}
行会破坏它。
<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
(IP 条件下不需要 NC 标志。)–怀特先生
谢谢。已删除。我找到了解决方案。它按预期工作:
<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>