0

I've noticed an 'error' in an .htaccess rule that I read in a tutorial. What I am trying to do is prevent access to wp-login.php using a very common .htaccess rule which is as follows:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.122$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.122$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteRule ^(.*)$ - [R=403,L]
</IfModule>

Now, the problem with this is that it creates an eternal 'loop' because the 403 page which the user with the invalid IP is sent to is then presented with a page that they cannot access. So, my question is - is it possible to hardcode a URL on the [R=403,L] line of code? I was thinking, perhaps something like:

 RewriteRule ^(.*)$ - [R=/folder/index.php,L]
0

I've found a solution - this needs to be added to the .htaccess

 ErrorDocument 403 /path-to-your-site/index.php?error=404

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.