Home » IT and Tech Blogs » Information Technology » Datacenter » Redirect web traffic via IP address; block and allow urls on webserver via IP address

Redirect web traffic via IP address; block and allow urls on webserver via IP address

Do you have a server which you would like a certain group of IP’s to see one thing, where another group of IP’s should redirect to alternate content?  This is most useful when you have two groups LAN users and WAN users accessing the same webserver, but you would like to forward each group to alternate directions.

Here’s a script you can place as your index file to forward IP traffic in two different directions.

<?php

$ip = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
$ip = explode(".", $ip);

//If IP = xxx.xxx; 10.0 is a class b network
If( $ip[0] . '.' . $ip[1] == '10.0') {
//redirect to
header("Location: http://url.com/this-link.html");
exit;
}

//Optional redirect for 2nd subnet: If IP = xxx.xxx; 10.2 is a class b network
If( $ip[0] . '.' . $ip[1] == '10.2') {
//redirect to
header("Location: http://url.com/this-link.html");
exit;
}

//Redirect all other traffic to www.url.com
header("Location: http://www.url.com"); 

?>

Lastly, you may not want that link (ex: http://url.com/this-link.html above) exposed to the outside world.

In apache, add to: httpd.conf

<Files "http://url.com/this-link.html">
    Order deny,allow
    Deny from all
    Allow from 192.168.1.0/255.255.255.0
</Files>

ad banner 619 3 - Redirect web traffic via IP address; block and allow urls on webserver via IP address

IIS7: http://technet.microsoft.com/en-us/library/cc730889.aspx


Thank you for reading IT Blog

ad banner 619 2 - Redirect web traffic via IP address; block and allow urls on webserver via IP address

Check Also

data breach21 310x165 - Who's Really Responsible for 3rd Party Vendor Breaches?

Who’s Really Responsible for 3rd Party Vendor Breaches?

Working with suppliers, partners, and third-party vendors has never been riskier to your bottom line. …

9 comments

  1. Works well for our office intranet!

  2. I like how you can use a php script to do this.

  3. karri_flournoy

    With havin so much written content do you ever run into any issues of plagorism or copyright infringement?

    My blog has a lot of completely unique content I’ve either authored myself or outsourced but it seems a lot of it is popping it up all over the internet without my agreement. Do you know any solutions to help reduce content from being ripped off? I’d genuinely appreciate it.

  4. Works well for our Intranet

  5. can you do this on the router?

  6. WOW just what I was looking for. Very accurate.

  7. Useful for routing internal and external traffic sharing the same webserver.

  8. Bahrain best Bahrain

    That saved us having to do rules on our appliance.

  9. Nice to know you can do it this way too.

Do NOT follow this link or you will be banned from the site!