.htaccess仅允许某些ip访问某些uri和文件

时间:2020-03-06 09:07:10

标签: wordpress .htaccess

我想阻止某些资源公开访问。我已经写了这个htaccess规则:

# Allowed IP
SetEnvIf Remote_Addr "^100\.100\.100\.100$" NETWORK=MYNETWORK
SetEnvIf Remote_Addr "^127\.0\.0\.1$"       NETWORK=MYNETWORK

# admin-ajax.php in under /wp-admin/ uri and all can access this file
RewriteCond %{SCRIPT_FILENAME} !^(.*)admin-ajax\.php$
# Only IP address from MYNETWORK can see "wp-login.php" and all resources under "/wp-admin/*" URI
RewriteCond %{ENV:NETWORK} !^MYNETWORK$
RewriteCond %{SCRIPT_FILENAME} ^(.*)?wp-login\.php$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin\/
# Rejected request are redirect on the home pahe
RewriteRule ^(.*)$ \/ [L,R=302]

我的规则不起作用!外部IP仍可以访问wp-login.php和/ wp-admin / *

0 个答案:

没有答案