发布前在 codeigniter 中更改 base_url

Change base_url in codeigniter before publsihing

我想发布我的 codeigniter 网站。

现在它位于“../htdocs/site/”文件夹中。 base_url 是:

$config['base_url'] = 'http://localhost/site'; 

我是否应该将 'site' 文件夹复制到真实服务器并像这样更改 base_url:

$config['base_url'] = 'http://example.com/site';

或者还有另一种方法可以隐藏 URL 中的“/site” ?

这是我的第一个项目,非常感谢您的帮助。

更新:

Root/
      -Application1
      -System1
      -Site1/
                    -index.php
                    -css
                    -js
                   -images
      -Application2
      -System2
      -Site2/
                    -index.php
                    -css
                    -js
                   -images

试试这个...

Move file from site directory to root directory and change root path index.php

$system_path = '../site/system';
$application_folder = '../site/application';

to 
$system_path = '../system';
$application_folder = '../application';

Change baseurl:$config['base_url'] = 'http://example.com/';

只需将 'site' 的内容(不是站点文件夹的内容)复制到服务器中的 public html 然后将 base_url 设置为 'http://example.com/

注意:如果在 htaccess 中使用 base 将其更改为仅 /

您不需要为每个环境重复您的应用程序。 Codeigniter 可以处理多种配置。您只需要为每个环境设置一个文件夹。

让我们假设以下组织:

Root/
      -Application
      -System
      -Assets           
         -css
         -js
         -images

      -index.php

我们将有 3 个环境:Dev/Testing/Production。

我们知道我们的应用程序会根据环境有不同的 base_url 和数据库 conf。这意味着每次我们将我们的应用程序从一个环境移动到另一个环境时,我们都需要修改 config.php 和 database.php。

CodeIgniter 为我们提供了一种简单的方法来做到这一点:

http://www.codeigniter.com/user_guide/general/environments.html

http://www.codeigniter.com/user_guide/libraries/config.html#environments

我们只需要在里面设置3个文件夹application/config

-application
      -config
         - development
         - testing
         - production

在这些新文件夹中,只需放置在每个环境中不同的配置文件。在我们的例子中,config.php 和 database.php

-application
      -config
         - development 
              -config.php
              -database.php
         - testing
              -config.php
              -database.php 
         - production
              -config.php
              -database.php
         - autoload.php
         - ...

最后,在根 index.php 中只需要修改以下行来告诉 CI 它在哪个环境中:

define('ENVIRONMENT', 'development'); //for dev env
define('ENVIRONMENT', 'testing'); //for testing env
define('ENVIRONMENT', 'production'); //for prod env

development/testing/production 是 CI 中的默认环境,但您可以通过在 application/config 中创建文件夹并修改根 index.php 中的开关来创建自己的环境:

switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(E_ALL);
    break;
    case 'server':
        error_reporting(E_ALL);
    break;
    case 'testing':
    case 'production':
        error_reporting(0);
    break;
   /*CUSTOM ENV :*/
    case 'custom_env':
        error_reporting(E_ALL);
    break;
    default:
        exit('The application environment is not set correctly.');
}