views:

148

answers:

2

Hi all, I am trying to make a multidomain setup of codeigniter.

I need to support links like this

www.site.com/users/username subdomain.site.com www.othersiteparkedonsite.com

in this 3 different cases i want to load application folder regarding the case

following code in index.php will work only with subdomain and domain case

// Application folder var
$myApp = '';

switch($_SERVER['HTTP_HOST'])
{
    case 'site.com':
        $myApp = 'application';
        break;

     default:
        $myApp = str_replace('.','_',$_SERVER['HTTP_HOST']);
        $myApp=str_replace('www_','',$myApp);
        $myApp='sites/'.$myApp;
    }

$application_folder = $myApp; 

but how to identify the first case and subdomains????

Using the code up I can do with only one folder /sites/ in root folder and load by subdomain name or domain name the folder but , how to make routing , or with htaccess so that I can load application folder regarding the username,subdomain, domain ,and controller??? I mean I need, if we go to www.site.com/users/usernameX

index.php will load /usersites/usernameX folder

in case of subdomains from

sub1.site.com will load application folder

/subdomains/sub1_site_com

in case of other domain parked on the same folder

www.otherdomain.com will load

/sites/otherdomain_com

and

www.site.com/somecontroller/somefunction will work from the main /application folder which is in the root ...

Can you help me?

A: 

Defined "does not work" as this should work fine. Does it simply load the default application?

var_dump() HTTP_HOST and compare it. If you are running on localhost:8080 or 8888 etc that will be included in HTTP_HOST so you might want to use SERVER_NAME instead.

Phil Sturgeon
actually all folders are simlinks inside the application folders, I will made universal content.php controller, which depending on site alias will give specified content....
DR.GEWA
What does that have to do with the price of fish?
Phil Sturgeon
ok, I could arrange so thet the right folder of application is loaded. But i have a problem with linksHow to make such routing thatwww.site.com/sites/userX/controller/function/var1/var2 will behave like it waswww.site.com/controller/function/var1/var2???
DR.GEWA
A: 

my solution is

$myApp = '';

    switch($_SERVER['HTTP_HOST'])
    {
        case 'multi.com':   





            $myApp = 'application';

            $uri_string=$_SERVER['REQUEST_URI'];

            if(strlen($uri_string)>6){


                $link_way=explode('/',$uri_string);
                //print_r($link_way);
                //var_dump($link_way);

                //проверяем если линк ведет к сайту юзера и у юзернейм состоит из более 4х знаков
                if($link_way[1]=='sites' and strlen($link_way[2])>=5){


                    $myApp='sites/usersites/'.$link_way[2];



                    }
                elseif($link_way[1]=='sites' and strlen($link_way[2])<5){
                    exit('Username should be more than 4 chars');

                    }






                }





            break;

         default:
            $myApp = str_replace('.','_',$_SERVER['HTTP_HOST']);
            $myApp=str_replace('www_','',$myApp);
            $myApp='sites/domains/'.$myApp;
        }

    $application_folder = $myApp;
DR.GEWA