Home > Programming, Servers & Scripts >

How can I set up a simple redirect based on an IP? httacess? (7)


10-24-2013 01:37 AM #1 kevins (Member)
How can I set up a simple redirect based on an IP? httacess?

How can I set up a simple redirect based on an IP I supply? httacess?

I don't run Apache I run litespeed.


10-24-2013 06:14 PM #2 bbrock32 (Administrator)

You can do it via PHP.

Code:
<?php
$ip=$_SERVER['REMOTE_ADDR']
if($ip=="1.1.1.1")
   header("Location: http://myredirect.com");
else
   header("Location: http://mynormalpage.com");
?>
Replace 1.1.1.1 with the ip you want to check and the two urls to be redirected in case it matches and if not.


10-24-2013 07:50 PM #3 kevins (Member)

Thank you Brock.

And that goes on my Index page where?

Also, how may I add adnl IP's to that?


10-24-2013 08:46 PM #4 bbrock32 (Administrator)

That goes on top of your index.php page.

What you mean by "add adnl IP's"?


10-24-2013 08:55 PM #5 kevins (Member)

Can I add more IPs to have the script redirect?

Example seperated by commas:

if($ip=="1.1.1.1, 1.1.2.3, 6.5.6.7")

So I add this to my index and save it as a php?


10-25-2013 08:00 AM #6 andyvon (AMC Alumnus)

Use the following:

Code:
if ($ip=="1.1.1.1" || $ip=="2.2.2.2" || ip=="3.3.3.3")


10-25-2013 10:10 AM #7 bbrock32 (Administrator)

What andyvon posted above will do the trick.


Home > Programming, Servers & Scripts >