有没有一种简单的方法可以在 codeigniter 上创建子域? [英] Is there an easy way to create subdomains on codeigniter?

查看:29
本文介绍了有没有一种简单的方法可以在 codeigniter 上创建子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在 codeigniter 上创建子域,例如 api.site.com?

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

推荐答案

您采用的方法取决于子域与主站点的不同之处.如果它们非常相似并且将使用相同的代码库:

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

然后您可以将每个 htdocs 文件夹中的 index.php 文件指向 common/system 目录.您还可以将要在所有子域之间共享的代码放在 common/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.

这篇关于有没有一种简单的方法可以在 codeigniter 上创建子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆