As part of our protection against attacks on WordPress, we block access to wp-login.php. Access is allowed only from the Czech Republic and Slovakia, which we enforce with the Apache module mod_geoip (documentation).
If you try to connect from anywhere else, you’ll see this warning:
“Zakazan pristup mimo SK a CZ. skrze .htaccess povolte svou IP” (Access denied outside SK and CZ. Allow your IP via .htaccess.)
How do you allow access from abroad?
Add the following code to your .htaccess file:
(choose one of the color-coded options: allow by IP / password-protected access)
[code]
<IfModule mod_geoip.c>
<FilesMatch “wp-login.php”>
SetEnvIf GEOIP_COUNTRY_CODE SK AllowCountry
SetEnvIf GEOIP_COUNTRY_CODE CZ AllowCountry
Require all denied
Require env AllowCountry
# for IP address 1.2.3.4
Require ip 1.2.3.4
</FilesMatch>
</IfModule>[/code]
Blocking with username and password authentication
[code]
AuthType Basic
AuthName “WP login“
# absolute path to the .htpasswd file with users and passwords
AuthUserFile /DISKx/www/customerid/domain.tld/subdomain/.htpasswd
Require valid-user[/code]
To allow access from anywhere in the world (not recommended):
[code]
<IfModule mod_geoip.c>
<FilesMatch “wp-login.php”>
Require all granted
</FilesMatch>
</IfModule>[/code]
Why do we block access?
- Most attacks on wp-login.php come from abroad. A targeted attack can completely “knock out” a site or slow it down significantly.
- If an attacker cracks the password and gets into the WordPress admin, the site gets infected with malicious scripts.
- Malicious scripts can damage the site irreversibly and stop it from working altogether.
- By the time anyone notices the site has been compromised, a lot of time has passed, and the only way to fix it is to restore it from backups.
Security comes first!
Sometimes there’s really no way around it and you need unblocked access to your site. It can be as simple as traveling or working with partners or users abroad. In that case, use the code above to turn off the blocking.
If you turn off the blocking, use a security plugin (e.g., iThemes Security). Installing the plugin and setting up its security features will take a little while, but trust us, it’ll save you plenty of time down the road and spare you a lot of trouble.
