CodeIgniter Forums
how to prevent redirect function adding index.php to urls - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to prevent redirect function adding index.php to urls (/showthread.php?tid=736)



how to prevent redirect function adding index.php to urls - sneakyimp - 01-11-2015

I'm using the CI function redirect in my web app. The problem I'm having is that if I redirect a user to /some/path/internally, then the redirect function inserts "index.php" into the url it redirects to. For example I created a controller Test:
Code:
class Test extends CI_Controller {
 public function index() {
   die(site_url("/some/path/internally"));
 }
}
The output is this:
Code:
http://example.com/index.php/some/path/internally
whereas I'd rather have it be:
Code:
http://example.com/some/path/internally
or even just
Code:
/some/path/internally

Is there some configuration setting I'm missing or something?


RE: how to prevent redirect function adding index.php to urls - Wei - 01-11-2015

(01-11-2015, 03:59 PM)sneakyimp Wrote: I'm using the CI function redirect in my web app. The problem I'm having is that if I redirect a user to /some/path/internally, then the redirect function inserts "index.php" into the url it redirects to. For example I created a controller Test:

Code:
class Test extends CI_Controller {
 public function index() {
   die(site_url("/some/path/internally"));
 }
}
The output is this:

Code:
http://example.com/index.php/some/path/internally
whereas I'd rather have it be:

Code:
http://example.com/some/path/internally
or even just

Code:
/some/path/internally

Is there some configuration setting I'm missing or something?

apache
mod_rewrite
.htaccess
Big Grin


RE: how to prevent redirect function adding index.php to urls - pdthinh - 01-11-2015

(01-11-2015, 06:06 PM)Wei Wrote:
(01-11-2015, 03:59 PM)sneakyimp Wrote: I'm using the CI function redirect in my web app. The problem I'm having is that if I redirect a user to /some/path/internally, then the redirect function inserts "index.php" into the url it redirects to. For example I created a controller Test:


Code:
class Test extends CI_Controller {
 public function index() {
   die(site_url("/some/path/internally"));
 }
}
The output is this:


Code:
http://example.com/index.php/some/path/internally
whereas I'd rather have it be:


Code:
http://example.com/some/path/internally
or even just


Code:
/some/path/internally

Is there some configuration setting I'm missing or something?

apache
mod_rewrite
.htaccess
Big Grin

application/config/config.php:
$config['index_page'] = "" // => remove "index.php"


RE: how to prevent redirect function adding index.php to urls - Avenirer - 01-12-2015

And... to promote myself (again...): http://avenir.ro/codeigniter-tutorials/removing-the-index-php-from-the-url-and-allow-the-use-of-search-engine-friendly-urls/


RE: how to prevent redirect function adding index.php to urls - InsiteFX - 01-12-2015

site_url() adds index.php to the url use base_url() to get rid of it.


RE: how to prevent redirect function adding index.php to urls - Avenirer - 01-12-2015

(01-12-2015, 04:52 AM)InsiteFX Wrote: site_url() adds index.php to the url use base_url() to get rid of it.

That will happen only if config['index_page'] has 'index' as value.