Skip to content
Advertisement

Codeigniter 3 redirection adds index.php to every redirect

this is a function in my controller

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

function is deleting properly my record but it redirects the user to

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

which gives me error 404

my .htaccess is like this:

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

i have set the index_page in config.php

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

Advertisement

Answer

Removing the index.php file in Codeigniter

By default, the index.php file will be included in your URLs:

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

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the “negative” method in which everything is redirected except the specified items:

And set your $config[‘index_page’] = ”;

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

In the above example, any HTTP request other than those for existing directories and existing files is treated as a request for your index.php file.

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement