Welcome Guest, Not a member yet? Register   Sign In
Domain & Subdomain Masking
#1

[eluser]psychobob[/eluser]
Hi all,

Thanks for looking at this. I will be having a codeigniter application that will be replacing a very non-global system that is written in ColdFusion. They have 15 exact replications of the same code but with different root folders. So each time I make a change to the code, I have to upload it 15 different times.

But making it a global system using codeigniter may not be possible... I hope someone can help me out here.

If a I have 3 foreign subdomains that I want to point to my codeigniter application

myaccount.xyz.com = approot/controllers/myaccount/
signup.xyz.com = approot/controllers/signup/
admin.xyz.com = approot/controllers/admin/

Now, I've done this successfully for a single domain by using the config file and setting the base_url to http://xyz.com

but unfortunately, I have to complicate things and try to service 15 different sites with the same application.

For example:
myaccount.xyz.com, myaccount.abc.com, myaccount.def.com, etc all point to approot/controllers/myaccount

There isn't much of a problem just pointing the sites there, it's that the base_url in the config file is static.

My thoughts are these:

1.) Grab the referring URL such as signup.xyz.com
2.) Break it apart:
Code:
$dom[1] = 'signup'; $dom[2] = 'xyz'; $dom[3]='com';
3.) Set session variables, such as
Code:
$this->session->set_userdata('controller') = $dom[1]
4.) Place that referring URL dynamically in the base_url of the config file. Such as:
Code:
$config['base_url'] = 'http://'.$this->session->userdata('controller'). '.' .$this->session->userdata('domain'). '.' .$this->session->userdata('extension').'/'.$this->session->userdata('controller')

I'm pretty sure there's a method for mod_rewrite that would make this simpler though...
something along the lines of this:
Code:
^/somepath(.*) http://otherhost/otherpath$1 [P]

But I am not strong on the server stuff, so I'm not exactly sure I understand mod_rewrite.

Any help would be very appreciated.
#2

[eluser]psychobob[/eluser]
I just wanted to let you know that the proposed method did 'work'. I'm not sure if it leaves me open to any particular security risks, so if anyone has any insight on that, I'd appreciate it.

Final Code in /system/application/config/config.php:
Code:
//change the base_url variable dynamically so we can globalize
            // Get the current host, or 'referrer'
            $ref = $_SERVER['HTTP_HOST'];
            // separate it into parts
            $dom=explode(".",$ref);
            if(count($dom)>=3) // in my case I want to make sure there's a subdomain
            {
                $config['base_url']    = "http://".$dom[0].'.'.$dom[1].'.'.$dom[2]; // config dynamic if everything is true
            } else {
                $config['base_url']    = "http://somedomain.com"; // config hardcoded url if not
            }




Theme © iAndrew 2016 - Forum software by © MyBB