php - Allow access to all files from only 1 IP address and redirect all others to other file -


i'm not sure if has been answered before tried looking it. anyways, i'm developing website make actual site content accessible ip address. want .htaccess redirect other ip address separate file on server. 1 file called subscribe.php.

i've tried couple things nothing provided me result wanted. know server allows .htaccess used since i've used change other things such preventing caches.

you can use mod_rewrite that. add following in .htaccess file:

code:

options +followsymlinks rewriteengine on rewritecond %{remote_addr} !=123.45.67.89 rewriterule index.php$ /subscribe.php [r=301,l] 

alternative solution:

<?php $allow = array("123.456.789", "456.789.123", "789.123.456"); //allowed ips  if(!in_array($_server['remote_addr'], $allow) && !in_array($_server["http_x_forwarded_for"], $allow)) {      header("location: http://domain.tld/subscribe.php"); //redirect      exit();  } ?> 

hope helps!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -