Welcome Guest, Not a member yet? Register   Sign In
Simple subdomains handler for CI3
#1

(This post was last modified: 04-04-2016, 10:05 AM by josepostiga. Edit Reason: Added validation warning )

Hey guys. Just wanted to share some useful knowledge on how to detect, and use, multi app system detection for CI3. It's pretty simple and straight-forward.

Edit your root index.php.
On the line where we define the $application var (default index.php set this to application), replace it with this:

PHP Code:
// checks domain
$domain explode('.'$_SERVER['HTTP_HOST']);

// switch domains
 switch ($domain[0]) {
     case 'admin':
         $application_folder 'admin';
         break;

     case 'bo':
         $application_folder 'bo';
         break;

     case 'api':
        $application_folder 'api';
        break;

     default:
         $application_folder 'application';
         break;
 

I use this to handle my SaaS apps, where I can map specific subdomains to different application's folders or use the default one to handle the customer specific application.

Please note that you should have some kind of validation for the subdomains you use here. See below for more details (thanks @albertleao).

This is probably one of many ways to do it. If you have done it differently, please share here!
Best regards,
José Postiga
Senior Backend Developer
Reply


Messages In This Thread
Simple subdomains handler for CI3 - by josepostiga - 04-04-2016, 06:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB