0

What is happening:- testurl.com/index.php/controller/method and testurl.com/controller/method, these both redirect to the same page that is index.php Requirement:- When somebody type testurl.com/index.php/controller/method/ the url must be change to testurl.com/controller/method after loading the same page that is index.php

They are loading same page currently but the url is not getting change.

Codeigniter is new for me I know its very simple task, but I am blank at this point. Any help will be appreciated. Thanks in advance.

2 Answers 2

2

I assume you want to remove index.php from the url

first : in config file set $config['index_page'] to blank i.e

$config['index_page']='';

Second : place the .htacess file in the app root folder

.htaccess file content :-

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js)
RewriteRule ^(.*)$ ./index.php/$1 [L]

get more info here : - Documentation

4
  • Its working fine but there is 1 problem that when I pass testurl.com/index.php/controller/ It redirect to testurl.com/index.php means If I pass the controller with index.php it redirect to the index page. However I wanted to redirect to view called by controller not at testurl.com/index.php
    – Nitu Dhaka
    Commented Jul 14, 2014 at 7:07
  • @NituDhaka this shouldn't be occur.this may be because of your server config.now you shouldn't use index.php in the url. Commented Jul 14, 2014 at 7:13
  • Yes I know it, I should not use index.php in url but this is the requirement that is why I wanted to learn about rewrite rule can you please explain the above lines?
    – Nitu Dhaka
    Commented Jul 14, 2014 at 7:21
  • mentioned in doc : any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file. Commented Jul 14, 2014 at 7:26
0

To check if the guy is at the index.php-Version of your URL you test your base_url:

if(strpos(current_url(), "index.php") !== false)

(as in [1])

Then you can redirect him to base_url()/uri_string() with:

redirect(base_url().'/'.uri_string()); 

to see more play around with the url-helper.

[1] http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.