Hey everybody,
I face this issue, and read and test all the suggestions on this forum.
clearing the cache and all other solutions, including turning off plugins and more.
Whitelisting to firewall etc.
Nothing worked for me.
Till I added the IP’s and add an rewrite rule to the .htaccess file.
BEGIN WordPress
The directives (rules) between “BEGIN WordPress” and “END WordPress” are
dynamically generated and should only be modified via WordPress filters.
Any changes to the directives between these markers will be overwritten.
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
Allow access to /wp-json/ only for specific IP addresses
RewriteCond %{REQUEST_URI} ^/wp-json/ [NC]
RewriteCond %{REMOTE_ADDR} !(34.254.1.9|52.31.156.93|52.50.32.186|54.75.157.176|54.78.149.203|52.18.144.195) [NC]
RewriteRule .* - [F,L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
END WordPress
This solved my issue.
1 Like
Thanks for this. Since I get this error intermittently. Works fine, then this error, then it can work fine again. I just want to confirm that is solved it for good for you? Can you help me explain exactly where to add this in my .htaccess (i was a little confused by your instruction here)
What does this do?
- RewriteCond %{REQUEST_URI} ^/wp-json/ [NC] → Checks if the request is for /wp-json/.
- RewriteCond %{REMOTE_ADDR} !(34.254.1.9|52.31.156.93|52.50.32.186|54.75.157.176|54.78.149.203|52.18.144.195) [NC]
- If the request does NOT come from one of these IP addresses, the rule is triggered.
- Note: The IP addresses must be escaped with a backslash (
\.
) due to regex rules.
- RewriteRule . - [F,L]* → If the above conditions are met, this denies access with a 403 Forbidden status.
Obvious, I took the IP addresses for EU, if you are in the USA you might add those to your .htaccess file.
2 Likes
Seems that despite this solution is working for a short time, the main issue is at the webserver. I noticed that when you using the caching function on nginx or apache this cache is keeping the issue alive. My suggestion in additional to this is to clear that cache as well. Even if possible reset the webserver to avoid it is using old settings over new settings.
in case none of this is working. Switch off the caching feature of nginx.