【问题标题】:Removing index.php in Codeigniter gives 404 error在 Codeigniter 中删除 index.php 会出现 404 错误
【发布时间】:2019-12-09 17:04:31
【问题描述】:

这是我的在线托管目录结构

-- /
   -- up
   -- .logs
   -- public_html
      -- application
      -- system
      -- user_guide
      -- .htaccess
   -- DO_NOT_UPLOAD_HERE

在我的 config.php 中,我写了这段代码:

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

在我的 .htaccess 文件中,我有以下代码:

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

我试图从我的 URL 中删除 index.php,所以它会显示 mydomain.com/class/controller 而不是 mydomain.com/index.php/class/controller

它在我的本地主机中运行顺利,我使用的是带有 LAMPP 服务器的 Ubuntu 15.10。但是,当我在线尝试所有代码时,它显示了 404 错误页面。

这是我即将上线的网站:onesource.esy.es

我的代码有什么问题?

【问题讨论】:

    标签: .htaccess codeigniter


    【解决方案1】:

    您的 mod_rewrite 规则正在重定向到 /index.php 而不是 /codeigniter/index.php。

    把它放在你的 .htaccess 文件中:

    RewriteBase /codeigniter/

    【讨论】:

    • codeigniter 来自哪里?因为我没有任何具有此类名称的文件夹。我所有的 codeigniter 目录都存储在一个名为 public_html 的文件夹中
    【解决方案2】:

    在我的实例中(使用 CI 3),我更改了配置中的 uri_protocol。尝试转到 application/config/config.php 并更改为:

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

    希望这会有所帮助。如果没有,也许这里有更多建议:

    CodeIgniter removing index.php from url

    【讨论】:

      【解决方案3】:

      在.htaccess文件中添加以下代码

      .htaccess 文件必须位于 CodeIgniter 项目文件夹的根目录中。

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

      在application/config/config.php文件中

      $config['enable_query_strings'] = FALSE;

      默认为false,改为TRUE

      $config['enable_query_strings'] = TRUE;

      然后再次尝试在没有 index.php 的浏览器中访问您的控制器

      我希望这对你有用。 (根据 CodeIgniter 版本 3)

      【讨论】:

        猜你喜欢
        • 2018-10-24
        • 1970-01-01
        • 2012-07-17
        • 2019-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-08
        相关资源
        最近更新 更多