25

I'm working on a site with a few controllers, and have configured my server to redirect requests for http://www.host.com/controller/function/params tohttp://www.host.com/index.php/controller/function/params using some simple regular expression matching in the apache config. Now, I am trying to get one of my controllers to redirect to another one, but without adding the index.php to the URL, which is what the redirect() function does. Is there an easy way to do this in codeigniter? Thanks beforehand!

3 Answers 3

88

You can use redirect. It only adds index.php if it is configured as your index page.

So, check your index_page configuration. It should be an empty string:

$config['index_page'] = '';

File: app/config/config.php

More info: http://www.codeigniter.com/user_guide/general/urls.html?highlight=mod_rewrite [Updated Version]

3
  • By the way, does that config parameter affect anything else in codeigniter or is it strictly for the redirect?
    – SuperTron
    Commented Feb 29, 2012 at 4:58
  • If affects several URL related functions, like site_url(), for example (which btw is used by redirect)
    – J. Bruni
    Commented Feb 29, 2012 at 5:31
  • worked in Codeigniter 4 in app/config/App.php
    – codelone
    Commented Dec 28, 2023 at 4:47
1

I used $config['index_page'] = ''; it worked.

0

you needs to add another .htaccess to root folder of your codeignitor based project and write there some redirect rules as below example :

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

or can make below in application/config/config.php

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.