Multiple domains pointing to single codeigniter

I'm new in Codeigniter and using Codeigniter v3. I'm trying to keep things somewhat easy to maintain for myself with shared config and models etc. I have several parts to my CodeIgniter which would be accessed through a subdomain, but internally would just be a controller folder. For example:

I need your help to give some solution to my questions:

  1. how to set up my Codeigniter so that fits my case?
  2. for the landing page, the best solution create a folder or not?

Upvotes: 1

Views: 1482

Answers (2)

Achuth Varghese
Achuth Varghese

Reputation: 2451

This is a case of managing multiple applications in Codeigniter. Some may have different approach from what I've mentioned below which may/may not include virtual host configuration.

Assuming you have an empty public_html folder for your domain.com ( maybe, have some default folders and an index file )

First thing to be done is create the subdomains that you intend to have. api, admin and dashboard are the mentioned ones.

Creating the subdomains will create sub-folders api, admin and dashboard in public_html folder.

Upload the codeigniter zip file and extract it to the public_html folder. Now the public_html folders would have folders: api, admin, dashboard, application, system, index.php ,etc.

Create folders api, admin, dashboard, landing in application folder. Copy all the files and folders there were already in the application folder into api, admin, dashboard and landing. Now, the application folder will have only 4 folders: api, admin, dashboard and landing.

Copy and paste index.php file in public_html folder to the folders api, dashboard and admin there is in the public_html folder.

Change the values of $system_path and $application_folder in the index.php file in the subdomain folders api, admin, dashboard. Here's an example for the subdomain api. These code lines will be seen near to line 90 in api/index.php file :

/*
 *---------------------------------------------------------------
 * SYSTEM DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" directory.
 * Set the path if it is not in the same directory as this file.
 */
    // $system_path = 'system'; // change this line
    $system_path = '../system';

/*
 *---------------------------------------------------------------
 * APPLICATION DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * If you want this front controller to use a different "application"
 * directory than the default one you can set its name here. The directory
 * can also be renamed or relocated anywhere on your server. If you do,
 * use an absolute (full) server path.
 * For more info please see the user guide:
 *
 * https://codeigniter.com/user_guide/general/managing_apps.html
 *
 * NO TRAILING SLASH!
 */
    // $application_folder = 'application'; // change this line
    $application_folder = '../application/api';

likewise for admin:

    // $system_path = 'system'; // change this line
    $system_path = '../system';

    // $application_folder = 'application'; // change this line
    $application_folder = '../application/admin';

for dashboard:

    // $system_path = 'system'; // change this line
    $system_path = '../system';

    // $application_folder = 'application'; // change this line
    $application_folder = '../application/dashboard';

for landing:

    // $system_path = 'system'; // change this line
    $system_path = '../system';

    // $application_folder = 'application'; // change this line
    $application_folder = '../application/landing';

By now you will be able to access:

  • api.domain.com --> domain.com/api (for API)
  • admin.domain.com --> domain.com/admin (for internal user)
  • dashboard.domain.com --> domain.com/dashboard (for client user)
  • domain.com --> domain.com

Upvotes: 1

Bilal
Bilal

Reputation: 9

it will be better if You use slack for these kind of projects which can be accessed by many sub domains

Upvotes: 0

Related Questions