是否有一种简单的方法可以在 codeigniter 上创建子域,例如 api.site?
Is there an easy way to create subdomains on codeigniter like api.site?
推荐答案您采用的方法取决于子域与主站点的不同之处.如果它们非常相似并且将使用相同的代码库:
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'] = ''.$_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': // settings specific to www subdomain $config['foo'] = 'bar'; break; case 'apl.example': // 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 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 上创建子域?
发布评论