Avatar of Jonathan Duane
Jonathan Duane
 asked on

Redirecting domain to sub domain

Hi Guys, i have a domain video.flyefit.ie with lots of subdomains, when people open up a browser based on their IP address i would like if it forwarded onto one of the subdomains so say for instance my ip is and i open up video.flyefit.ie i would like it to redirect to video.flyefit.ie/blanch is this possible?
HTMLPHPDNSApache Web Server

Avatar of undefined
Last Comment
David Favor

8/22/2022 - Mon
Julian Hansen

Firstly - are the IP's guaranteed to be static?

If so you build an IP -> subfolder lookup
$lookup = [
  '' => '/folder1',
  '' => '/folder2'

$ip = getIPAddress(); // Custom function see below

$destination = isset($lookup[$ip]) ? $lookup[$ip] : false;
if ($destination) {
  header('location: ' . $destination);
} else {
   // handle error

function getIPAddress(){
        //ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
        //ip pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $ip = $_SERVER['REMOTE_ADDR'];
    return $ip;

Open in new window

Note: The above code is untested but it demonstrates the concept.

The getIPAddress() function was obtained from here https://www.w3resource.com/php-exercises/php-basic-exercise-5.php other examples are here https://stackoverflow.com/questions/15699101/get-the-client-ip-address-using-php
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
David Favor

Both of Julian's suggestions will work.

And if you have many users, your main budget may go toward dealing with visitor problems related to your IP routing, depends on your exact system.

Now the big question is what you hope to accomplish.

Keep in mind these days...

1) Many people use VPNs, so their IPs will constantly change.

2) Most people use cell devices, so their IPs may change as they bounce between cell towers + networks, depending on many factors.

5G is another consideration. No one knows yet, as implementations are rare + vary a great deal.

3) You can no longer make any Geo determination for a visitor on an IP, because of #1 + #2.

Suggestion: If required, open another question describing what you hope to accomplish + ask for design assistance.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy