删除Codeigniter中的index.php会产生404错误

时间:2016-03-17 13:01:00

标签: .htaccess codeigniter

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

-- /
   -- 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>

我尝试从网址中删除index.php,因此会显示mydomain.com/class/controller而不是mydomain.com/index.php/class/controller

它在我的localhost中运行顺利,我使用Ubuntu 15.10和LAMPP服务器。但是,当我在线上尝试所有代码时,它会向我显示404错误页面。

这是我即将成为工作的网站:onesource.esy.es

我的代码出了什么问题?

3 个答案:

答案 0 :(得分:0)

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

将它放在.htaccess文件中:

RewriteBase / codeigniter /

答案 1 :(得分:0)

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

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

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

CodeIgniter removing index.php from url

答案 2 :(得分:0)

.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)

相关问题