【问题标题】:how to set up second codeigniter app in subdomain如何在子域中设置第二个 codeigniter 应用程序
【发布时间】:2019-10-05 12:03:33
【问题描述】:

我有一个 web 应用的前端和后端,前端是在 codeigniter 框架中制作的,后端也是在另一个 codeigniter 框架中制作的。

前端:flum.com
后端:subdomain.flum.com

前端工作正常,但我在后端遇到了困难,它总是显示错误 404。

在我的共享主机文件管理器中,

前端 - codeigniter 应用程序 1

/root/username/application    
/root/username/system    
/root/username/public_html/index.php    
/root/username/public_html/public/(css, js, images folders)

后端 - codeigniter 应用程序 2

/root/username/subdomain_application
/root/username/subdomain_system
/root/username/public_html/subdomain/index.php
/root/username/public_html/subdomain/public/(css, js, images folders)

两者具有相同的数据库设置 应用程序/config/database.php

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'user',
    'password' => 'pass',
    'database' => 'mydatabase',
    'dbdriver' => 'mysqli',...
);

前端应用程序/config/config.php

$config['base_url'] = 'http://flum.com';
$config['index_page'] = '';

-我在主 ci 应用程序上编辑了 index.php

$system_path = '/root/username/application';
$application_folder = '/root/username/system';

后端应用程序/config/config.php

$config['base_url'] = 'http://subdomain.flum.com';
$config['index_page'] = '';

-我在主 ci 应用程序上编辑了 index.php

$system_path = '/root/username/subdomain_application';
$application_folder = '/root/username/subdomain_system';

两者都有相同的 .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

鉴于后端位于一个完全独立的 codeigniter 应用程序中,我预计后端将与我的前端应用程序一起正常工作。

【问题讨论】:

    标签: codeigniter subdomain hosting cpanel shared


    【解决方案1】:

    这是您可以尝试的另一种文件结构。希望它会带来更好的结果。

    /root/username/front/application/
    /root/username/front/public_html/index.php
    /root/username/front/public_html/.htaccess
    /root/username/front/public_html/assets/(css, js, images folders)
    
    /root/username/back/application/
    /root/username/back/public_html/index.php
    /root/username/back/public_html/.htaccess
    /root/username/back/public_html/assets/(css, js, images folders)
    

    前后可以使用同一个系统目录

    /root/username/system/
    

    前后都需要自己的index.php。各系统路径相同。

    /front/public_html/index.php

    $system_path = '/root/username/system';
    $application_folder = '/root/username/front/application';
    

    /back/public_html/index.php

    $system_path = '/root/username/system';
    $application_folder = '/root/username/back/application';
    

    两个“public_html”目录中都需要.htaccess,但它们与您在问题中显示的相同。

    您使用的 $config['base_url'] 值可以在相应的 config.php 文件中使用。

    因为您使用.htaccess 我假设您使用的是 Apache。 Apache 站点 conf 文件中的前后块都需要将 DocumentRoot 值设置为适当的 public_html 目录路径。

    问题中显示的数据库配置应该适用于正面和背面。

    CodeIgniter 文档对Running Multiple Applications 有另一个建议,类似于我展示的结构。它使用两个 index.php 文件,但至少其中一个必须具有不同的名称。在你的情况下,也许前面使用 index.php 而后面使用 backend.php

    要浏览到名为“admin”的后端控制器,URL 应为 https://subdomain.flum.com/backend.php/admin

    从 URL 中删除 index.php 或 backend.php 需要更复杂的 .htaccess。老实说,我不确定这是什么样的,以及呈现文件结构的原因。

    【讨论】:

      猜你喜欢
      • 2019-06-20
      • 2011-06-30
      • 2015-06-17
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多