I'm currently building a small business website and I'm hosting on a home server, and have hit a roadblock with not being able to enhance security because of Wordpress not following any of the rules I've put into .htaccess. I would like to preferably block access to the wp-login.php or wp-admin from other IP's than mine. So I used this bit of code that I'm finding all over the place:
ErrorDocument 401 /path-to-your-site/index.php?error=404
ErrorDocument 403 /path-to-your-site/index.php?error=404
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteCond %{REMOTE_ADDR} !^IP Address One$
RewriteCond %{REMOTE_ADDR} !^IP Address Two$
RewriteCond %{REMOTE_ADDR} !^IP Address Three$
RewriteRule ^(.*)$ - [R=403,L]
</IfModule>
, but that didn't work so I tried another bit:
# Block access to wp-admin.
order deny,allow
allow from x.x.x.x
deny from all
(keep in mind these are going in the .htaccess in the wp-admin as instructed, but that didn't work so I copied it and put one in the "html" folder and neither worked), but none of those worked so I thought that it must just be something with the code. So I decided that I could just password protect wp-login.php with the .htpasswd file being out of the "html" folder and this code in both of the .htaccess files:
# Protect wp-login
<Files wp-login.php>
AuthUserFile /var/www/.htpasswd
AuthName "Private access"
AuthType Basic
require user insertusernamehere
</Files>
, however that didn't work either, making me think that WP isn't even seeing any of the rules in there.
This is currently the code in both of the .htaccess files:
ErrorDocument 401 /var/www/html/wp-content/themes/zerif-lite/index.php?error=404
ErrorDocument 403 /var/www/html/wp-content/themes/zerif-lite/index.php?error=404
#Protect wp-login
<Files wp-login.php>
AuthUserFile /var/www/.htpasswd
AuthName "Private access"
AuthType Basic
require user wpsecure
</Files>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteCond %{REMOTE_ADDR} !^INSERTMYIPHERE$
RewriteRule ^(.*)$ - [R=403,L]
</IfModule>
(commented)Block access to wp-admin
order deny,allow
allow from INSERTMYIPHERE
deny from all
(commented)BEGIN WordPress
(commented)END WordPress
I've been fighting with this for a few days now, and have made little to no progress. I did look at this website: https://www.keycdn.com/support/htaccess-not-working/ to see if there was anything there, and apache "AllowOverride" was set "None" but changing it to "All" made no effect. I've tried to provide you with as much information, however, if you need more feel free to ask me.
AllowOverride
? You don't just set this - it needs to be set for the specific directory path you are using and make sure it's not overridden. What version of Apache? Do you haveAllowOverrideList
set as well?