Forum Topic: RewriteCond allow two ip addresses

Forum: .htaccess Forum : Security • Posted by Jeroen • Updated:

Jeff, me again.

So, I want to do a cronjob to a page to reset the pageviews once a week. And allow only the webhost and me to go to this page. With these lines

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^51\.21\.61 [OR]
RewriteCond %{REMOTE_ADDR} !^131\.221\.61\.91
RewriteCond %{REQUEST_URI} /reset-pageviews [NC]
RewriteRule ^(.*)$ index.php [F,L]

It looks like the first ip address (host) has access, but the second one (which is me, the creator of these wonderful lines) gets a 403. Why-o-why is this? I have double-checked my ip address.

Thanks for your time again!

2 Replies to “RewriteCond allow two ip addresses”

Posted by Jeff Starr

Hi Jeroen,

Great question! Try it without the [OR] flag on the first directive should get you there. When testing for multiple not (!) conditions, always use AND instead of OR.. Of course, with .htaccess, AND is implied, so this should work:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^51\.21\.61
RewriteCond %{REMOTE_ADDR} !^131\.221\.61\.91
RewriteCond %{REQUEST_URI} /reset-pageviews [NC]
RewriteRule .* index.php [F,L]
Posted by Jeroen •

Thanks Jeff, makes sense and I have learnt something again.

Now still puzzling to get a cronjob working on a WP page and life is great again.

Cheers!