2

I'm currently working on a production site where htaccess is blocking users that do not have my IP from accessing the site:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^11.22.33.44
RewriteCond %{REQUEST_URI} !^/brb/(.)*$ [NC]
RewriteRule ^(.*)$ /brb/index.html [R=307,L]

Maintenance mode, basically.

I've now realized, WP Crons are not running. And I'm trying to force them to run (WP Cron Control plugin) by selecting "run now". They're all stuck at "Running: (now)" but never execute.

I assume it has something to do with the htaccess, but do not know how to make an exception for wp-crons without allowing in all public traffic for a moment?

1 Answer 1

3

The .htaccess directives block any HTTP request not coming from your IP address. However, I believe WP Cron is also an HTTP request that originates from the server. So, you need to also make an exception for the server's external IP address.

These directives can also be simplified a bit...

For example:

RewriteCond %{REMOTE_ADDR} !=203.0.113.111
RewriteCond %{REMOTE_ADDR} !=11.22.33.44
RewriteRule !^brb/ /brb/index.html [R=307,L]

Where 203.0.113.111 is whatever your server's IP address is.

The = operator on the CondPattern makes it a lexicographical string comparison, as opposed to a regex, so no need for the start-of-string anchor (^) or escaping of literal dots (which you aren't doing anyway, but strictly should be).

No need for the additional condition that checks that the URL-path does not start /brb/, since this can be incorporated into the RewriteRule pattern. (And no need for the capturing groups, since you don't have any backreferences.)

1
  • That actually makes sense, I was thinking "localhost" instead vs the server's IP. I ended up just removing the htaccess restriction and instead adding an IP conditional to the root index.php temporarily. But this would likely be the winning solution Apr 11, 2020 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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