Redirect & Restrict Access to WP Admin except from specific IP

Restrict wp-login.php and /wp-admin/ Access by IP address utilizing .htaccess file(s).

By β™Ÿ Vondelphia.com β€” Updated Apr 1, 2021

Easily restrict WordPress admin access by IP using an Apache HTTP Server .htaccess file. You may have to View > Show Hidden Files” in your FTP Cyberduck / Filezilla client. Also, instead of /public/ your web server might call the folder something else.

Create a new .htaccess file and insert the following code in your /public/wp-admin/.htaccess file. Remember to change the redirect URL and IP address.

order deny,allow
# change your IPv4 address below
allow from 192.168.69.420

# IPv6 converter format example
# allow from 2601:5d:0098:5ee0::/64
deny from all

# redirect visitor URL
ErrorDocument 403 https://vondelphia.com

Here is a non-commented version of the .htaccess file you would place in your folder:

order deny,allow
allow from 192.168.69.420
deny from all
ErrorDocument 403 https://vondelphia.com
Redirect & Restrict Access to WP Admin except from specific IP
You should have two .htaccess files, one inside wp-admin and your main file in root

Limit Access to WordPress Login

You might not know, but if someone visits yourwebsite.com/login they can avoid and skip the .htaccess wp-admin block we just setup, so we want to block that too. Here is the code you'll add to the (near) top of the main .htaccess file:

<Files wp-login.php>
order deny,allow
allow from 192.168.69.420
deny from all

ErrorDocument 403 https://vondelphia.com/forums/
</Files>

If you tried to paste that snippet to the very top of your .htaccess file, it might break your WordPress website because it does not play well with the native RewriteRule and RewriteCond.

Was this helpful?

Yes! πŸŽ‰ No! πŸ˜‘

Not quite what you're looking for? Get Help

Discussion

Thank you for being part of the Von community.

Leave a Comment

Item added to cart.
0 items - $0