The process involves matching all requests for an
1 2 3 4 | RewriteCond %{REMOTE_ADDR} !^120\.120\.120\.120 RewriteRule ^admin/.* - [L,R=403] RewriteCond %{REMOTE_ADDR} ^120\.120\.120\.120 RewriteRule ^admin$ - [L,R=403] |
If you want to control this IP using a script, you can add 2 lines
###CUSTOM RULES### # your rules will appear here using php script ###CUSTOM RULES###
Now add a script, say happy.php
and use the following code:
1 2 3 4 5 6 7 8 9 10 11 | $htaccess = file_get_contents('.htaccess'); $ip= str_replace(".","\.",$_SERVER['REMOTE_ADDR']); $rules="RewriteCond %{REMOTE_ADDR} !^".$ip." RewriteRule ^admin/.* - [L,R=403] RewriteCond %{REMOTE_ADDR} !^".$ip." RewriteRule ^admin$ - [L,R=403]"; $problem="###CUSTOM RULES###\r\n".$rules. "\r\n###CUSTOM RULES###"; #please copy the next line carefully, no extra spaces or new lines $solution=preg_replace('/###CUSTOM RULES###.*?###CUSTOM RULES###/sm',$problem,$htaccess); file_put_contents('.htaccess', $solution); |
you can also specify your error page for specific http code: 403ErrorDocument 403 /er.htm
Leave a Reply