3

I am having a serious issue with one application developed in CI. Currently my URLs look like this

http://www.example.com/content/index/mission/

I want to remove /content/index/ from URL So, It should look something like this.

http://www.example.com/mission

I have routing and .htaccess method as well. But nothing seems to be working.

Here is my .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|css/js/style/system/feature_tab/robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

I have also tried routing of CI by defining reouters in config/router.php But it was not working :(

1
  • make sure you have mod_rewrite enabled and set AllowOverride to All in apache configuration. (Assuming that you have correctly created routes in routes.php) Commented Sep 29, 2011 at 22:24

2 Answers 2

4

For your specific example, you'll want to create a route (in application/config/routes.php) that maps

$route['mission/']

to

"content/index/mission"

In other words, $route['mission/'] = "content/index/mission";

See the CI documentation regarding URI routing for more info

Sign up to request clarification or add additional context in comments.

5 Comments

Now i removed trailing slash from $route['mission/'] and it is taking me to home page.
@Salman: Do you have anything relevant you can post from your .htaccess file? http://www.example.com/content/index/mission/ does NOT give you a 404, correct?
Yes, It does not give me 404 error. I have edited my question and now it have my .htaccess file as well. Thanks for your quick replies :)
What happens if you remove your .htaccess (keep the trailing slash in $route['mission/'], however) and try http://www.example.com/index.php/mission ?
@SalmanAslam: Do you have any other routing rules defined in routes.php? If so, can you post them?
1

You can go into application/config/routes.php and set your own URL routing rules. (i.e. use something totally different than Controller/Funcction). There should be an array called $route which lets you assign mappings of url => controller/function. Hope this helps.

Check out this guide, its right up you're alley:

http://codeigniter.com/user_guide/general/routing.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.