【问题标题】:Codeigniter showing 404 Page Not Found on HostgatorCodeigniter 显示在 Hostgator 上找不到 404 页面
【发布时间】:2023-03-09 00:34:01
【问题描述】:

我目前正在我自己的 Hostgator 帐户上测试我的 Codeigniter 项目。该项目在我的 WAMP 服务器上运行良好,但在 Hostgator 上在线时显示 404 Page Not Found 错误。我尝试过使用 FTP 上的文件权限来使用 .htaccess 文件。当前站点可以在这里查看:www.test.jeffreyteruel.com。

看看我的 .htaccess 文件:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我当前的文件结构:

-application
-assets (css/js/img files) 
-cgi-bin(from the server) 
-system
-uploads
-.htaccess
-index.php

这是我当前的 config.php 信息:

$config['base_url'] = 'http://test.jeffreyteruel.com'; 
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

route.php 文件中的默认控制器是:$route['default_controller'] = 'main';

主控制器(main.php):

<?php defined('BASEPATH') OR exit('No direct script access allowed');
   class Main extends CI_Controller {
      public function __construct() 
      { 
         parent::__construct(); 
         //insert model here    
         $this->load->model('main_model'); 
         date_default_timezone_set('Asia/Manila');       
       } 
      public function index()
      { 
        $content['main_content'] = 'home/home'; 
        $this->load->view('main',$content);
      } 
  ...  
  ?> 

任何帮助使网站正常显示将不胜感激。

【问题讨论】:

  • 如果你转到http://example.com/index.php 是否正确解决?
  • @Ohgodwhy 不。如果我转到您提到的链接,我会收到此消息:示例域 该域的建立是为了用于文档中的说明性示例。您可以在示例中使用此域,无需事先协调或请求许可。
  • @jeffrey Teruel Ohgodwhy 的意思是......如果你去test.jeffreyteruel.com/index.php 你会看到什么?由于它是一个实时站点,我们看到您找不到 404 页面。 jeffreyteruel.com/test/index.php 给出相同的结果。
  • @TimBrownlaw,我仍然遇到同样的 404 错误。既然是子域,我会检查如果我把它放在它自己的域上是否有任何区别。
  • 你在 routes.php 中的默认路由是什么。你有任何大写的文件夹名称吗?如果您禁用 .htaccess 并使用上面的完整链接会发生什么?

标签: php .htaccess codeigniter http-status-code-404 server


【解决方案1】:

我在 Hostgator 的一个子域上运行 CI,我记得要让它工作有点困难,但由于我年纪大了,我的记忆力就像……嗯,不记得了!

我的简化版 .htaccess 是

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

加法:

在你的 config.php 中

$config['base_url'] = 'http://test.jeffreyteruel.com';      

添加尾随/

$config['base_url'] = 'http://test.jeffreyteruel.com/';

更新:

使用 Codeigniter 3,所有类名都需要大写 - 第一个字母大写( ucfirst )。 参考:codeigniter.com/userguide3/general/styleguide.html#file-naming

【讨论】:

  • 我非常感谢您的帮助。
  • 好的,如果将配置更改为 $config['base_url'] = '';
  • 线索是 test.jeffreyteruel.com/index.php 导致 404。这通常表明未找到默认控制器,这可能是由于它的情况。那么你能对你的主控制器有所了解吗?
  • 刚刚用路由和 main.php 控制器文件更新了我上面的代码,供您和任何阅读本文的人使用。
  • 谢谢。您使用的是哪个版本的 CI?
猜你喜欢
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 2018-02-12
  • 2015-08-14
  • 2020-07-14
  • 2019-12-02
  • 1970-01-01
相关资源
最近更新 更多