Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

php - Is there an easy way to create subdomains on codeigniter?

Is there an easy way to create subdomains on codeigniter like api.site.com?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The approach you take depends on how different the subdomain is from the main site. If they are very similar and will be using the same codebase:

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';

If you need some settings to be different on a different subdomain, you could create a config file like so:

switch($_SERVER['HTTP_HOST']){
   case 'www.example.com':
       // settings specific to www subdomain
       $config['foo'] = 'bar';
   break;

   case 'apl.example.com':
       // settings specific to apl subdomain
       $config['foo'] = 'baz';
   break;
}

Another approach would include setting up a separate application folder for the subdomain, but pointing at the same system folder. If you organize your filesystem like this:

example.com
  common
    system
    application
  www
    htdocs
    application
  apl
    htdocs
    application

You could then point the index.php file in each htdocs folder at the common/system directory. You could also put code you want to share between all subdomains in common/application and include them from your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...