Codeigniter 3重定向将index.php添加到每个重定向

时间:2016-07-21 20:24:32

标签: codeigniter

这是我控制器中的一个功能

public function delete() {
    $result_id =  $this->uri->segment(3);
    $this->result_model->delete($result_id);
    redirect('results/all/');
}

函数正在正确删除我的记录,但它会将用户重定向到

http://localhost/ci/index.php/results/all

给了我错误404

我的.htaccess是这样的:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

我在config.php中设置了index_page

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

2 个答案:

答案 0 :(得分:2)

  

删除Codeigniter中的index.php文件

默认情况下,index.php文件将包含在您的网址中:

  example.com/index.php/news/article/my_article

如果您的Apache服务器启用了mod_rewrite,则可以使用带有一些简单规则的.htaccess文件轻松删除此文件。下面是这样一个文件的示例,使用“否定”方法,除了指定的项目之外,所有内容都被重定向:

  

并设置您的$ config [' index_page'] ='';

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

在上面的示例中,除了现有目录和现有文件之外的任何HTTP请求都被视为对index.php文件的请求。

http://www.codeigniter.com/user_guide/general/urls.html

答案 1 :(得分:0)

删除以下行中的index.php

$config['index_page'] = '';

htacces应为

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

确保命名转换正确