【问题标题】:Deploying codeigniter on heroku works fine on localhost but path issues on heroku在heroku上部署codeigniter在本地主机上工作正常,但在heroku上的路径问题
【发布时间】:2017-09-01 06:49:38
【问题描述】:

我正在使用 codeigniter 在 heroku 上部署一个简单的站点。它在 localhost (xampp) 上工作得很好,但在 heroku 上却不行。在 heroku 上它需要 index.php 并说无法加载模型“核心”并且它也区分大小写。我该怎么办?

当我跑步时

http://localhost/herokuroot/

我的页面加载但当我运行时

https://bugdevroots.herokuapp.com/

它说

404 Page Not Found

The page you requested was not found.

但它适用于

https://bugdevroots.herokuapp.com/index.php/Welcome

我的默认控制器是welcome

我已将其包含在我的.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
        ErrorDocument 404 index.php
</IfModule>

在我的 config.php 中

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

【问题讨论】:

    标签: php .htaccess codeigniter heroku


    【解决方案1】:

    我也遇到了同样的问题,到目前为止我就是这样解决的。

    首先,在您的routes.php 中,您必须设置您的页面

    $route['default_controller'] = 'pages/view';
    $route['(:any)'] = 'pages/view/$1';
    

    假设在您的 views 文件夹中,您有一个名为 pages 的文件夹,其中包含您网站中的页面。在routes.php 中添加这些后,转到config 文件夹中的autoload.php 并设置以下代码:

    $autoload['helper'] = array('url');
    

    然后将以下代码设置到config.php 文件夹内的config

    $config['base_url'] = 'your_heroku_link';
    $config['index_page'] = 'views/pages/home.php';
    $config['uri_protocol'] = 'REQUEST_URI';
    $config['sess_save_path'] = sys_get_temp_dir();
    

    在我的index_page' 中是一个文件路径,我的所有页面都存储在其中,home.php 是加载后的页面。

    设置完所有这些,只需将其推送到您的 heroku 上

    $ git push heroku master
    

    然后打开您的应用查看结果

    $ heroku open
    

    这可能不是正确的答案,因为我仍在修复在我的应用程序中加载 css 文件的问题。但如果您需要参考,可以在 github 上查看我的代码:https://github.com/OariKirian/fy-stories-inc

    【讨论】:

      【解决方案2】:

      在我的情况下,我找到了一个解决方案,首先将其部署到我自己的服务器上,但我遇到了同样的错误。 经过一些测试,我发现因为它是一个 linux 服务器,所以区分大小写! 因此,在使用第一个大写字母重命名我的控制器和模型文件后,现在一切正常。

      【讨论】:

        猜你喜欢
        • 2020-06-10
        • 2019-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-23
        • 1970-01-01
        • 2018-04-25
        • 2020-08-25
        相关资源
        最近更新 更多