【问题标题】:Page 404 CodeIgniter index.php第 404 页 CodeIgniter index.php
【发布时间】:2012-12-21 21:09:38
【问题描述】:

我有这个关于 Codeigniter 的问题,不幸的是,这个网站上关于这个问题的其他帖子对我没有帮助,或者我没有很好地应用它。

编辑* 添加屏幕截图:

我的目录结构:

  • 调度程序(主文件夹)
    • 系统
      • 应用程序
        • 配置(文件夹)
        • 控制器(文件夹)
          • BS.php
    • 以及其他文件夹和文件
    • index.php

正如标题所说,当我输入时

http://mysite.com/folder/index.php

它输出找不到页面 404。但是,当我输入 http://mysite.com/scheduler/index.php/BS 时,它显示“这是一个 BS 文件”,因为我使用下面的代码回应了它。

BS.php

 function index($flag = NULL)
{

 echo "This is a BS File.";
 }

routes.php

$route['default_controller'] = "BS";
$route['scaffolding_trigger'] = "";

index.php

error_reporting(E_ALL);

$system_folder = "system";

$application_folder = "application";

if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder); 
}

define('EXT', '.php');
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('FCPATH', str_replace(SELF, '', __FILE__));
define('BASEPATH', $system_folder.'/');

if (is_dir($application_folder))
{
    define('APPPATH', $application_folder.'/');
}
else
{
    if ($application_folder == '')
    {
        $application_folder = 'application';
    }
    define('APPPATH', BASEPATH.$application_folder.'/');
}

require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;

最后,我的 config.php

$config['base_url'] = "http://" . $_SERVER['HTTP_HOST']. "/scheduler/";
$config['secure_base_url'] = "https://" . $_SERVER['HTTP_HOST']. "/scheduler/";

$config['index_page'] = "index.php";

$config['uri_protocol'] = "REQUEST_URI";

现在做了几天,仍然没有一个过程给出。很高兴得到任何帮助。

【问题讨论】:

  • 你需要 HTACCESS 从 URL 中删除 INDEX.PHP
  • 它按预期工作。这里有什么问题?
  • 我编辑了我的问题,请查看我的问题的最上方部分,您会看到我的问题的屏幕截图。
  • 看起来肯定是个废话。你试过$config['uri_protocol'] = 'AUTO';吗?此外,如果可能,请尝试升级到最新版本的 Codeigniter。看起来您仍在使用版本 1。
  • @itachi:我认为他用作示例的“folder/index.php”URL 不正确/错误 - 查看屏幕截图地址栏中的 URL,这应该可以澄清。哦,+1,因为韦斯利必须团结起来;)

标签: php codeigniter controller routes http-status-code-404


【解决方案1】:

终于知道怎么做 如上我的问题,还记得目录结构吗?

在 Controller 文件夹中,我有这个 BS.php 文件。然后,如果我没记错的话,这与文件的大小写敏感有关。这可能是由于域不支持文件名中的大写字母,我在本网站其他问题的一些答案中读到了它。

简而言之,我将 BS.file 制作成了 bs.file。它奏效了。

编辑

另外,在 routes.php 中,我将 BS 更改为 bs。

【讨论】:

  • 并且不要忘记更改stackoverflow.com/a/14807463/1537413中提到的apache配置
【解决方案2】:

我看到你已经发布了 index.php 的代码。我认为您不需要,因为您应该尽量不要在那里编辑任何内容。

您的根文件夹中有 .htaccess 吗?

每当我开发任何 CI 应用程序时,我总是将这个 .htaccess 文件放在手边。

http://pastebin.com/nTsThZHv

【讨论】:

  • 我将 .htaccess 放在我的根目录中仍然无法正常工作。我什至覆盖了我的 .htaccess 你给我的东西,仍然不起作用。 :l
【解决方案3】:

您应该从 index.php 文件中删除代码并在您的 Web 应用程序的根目录中创建 .htaccess 文件。 (即应用程序,系统文件夹存在)。

这是我重复的答案: Codeigniter issues with paths in localhost (XAMPP)

请在项目文件夹中创建 .htaccess 文件并写入:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

你不需要在配置文件的base_url中定义:

$config['base_url'] = ''; // blank it.

【讨论】:

    【解决方案4】:

    就我而言,这是控制器的案例问题,但与@Brain 的答案略有不同。 这是因为我使用了一个名为“AxxxxBxxx.php”的默认控制器。我总是收到 404 错误。 在我将其更改为“Axxxxxxxxxxx.php”并更改相应的类名之后。 它有效。

    顺便说一句,我使用 codeigniter 3.0。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-17
      • 2012-08-07
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2012-06-02
      • 1970-01-01
      相关资源
      最近更新 更多