Home > Mobile >  Crontab being blocked by htaccess even Whitelisted
Crontab being blocked by htaccess even Whitelisted

Time:07-18

I'm trying to block all access except my own and my server to my two scripts, but when I try to make a crontab to run my scripts, I get the error 403 forbidden even with my server IP being whitelisted in my htaccess.

This is my .htaccess

Options  FollowSymlinks
RewriteEngine on
#the urls that should be checked
RewriteCond %{REQUEST_URI} ^(/script.php|/script2.php).*$
RewriteCond %{REMOTE_ADDR} !=194.1....(My server Ip)
RewriteCond %{REMOTE_ADDR} !=0.0.0.0
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=172......(My Ip)
RewriteRule ^.*$ / [F]

this is my crontab (i'm using hostinger panel)

wget -O /dev/null mydomain.com/script.php/  

This is the error

--2022-07-15 09:30:02--  mydomain.com/script.php
Resolving mydomain.com (mydomain.com)... 2a02:4780:b....., 194.1....(my server ip)
Connecting to mydomain.com(mydomain.com)|2a02:4780:b:....|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2022-07-15 09:30:02 ERROR 403: Forbidden.

and if i run manually from my ip , it works fine. So is there a way i can make my script run as a crontab and not accessible by url by others. only by me and by my server

CodePudding user response:

I think i Got it , I just added this line before the RewriteCond %{REMOTE_ADDR} and is working now , no one can access via url , and the server can access normaly

RewriteCond %{HTTP_USER_AGENT} !^Wget [NC]
  • Related