Yet another mod_rewrite question


I've have been browsing these forums and the CI wiki for more than 3 hours now and I thought that it was high time that I asked the gurus for help rather than wasting any more of my evening. I am relatively new to CI (but not to programming) and even more of a newbie when it comes to using mod_rewrite.

After following the various examples found here, I have successfully changed the way that a visitor to my website accesses it, by changing the address from to

I have also set:
$route['default_controller'] = 'controller';
so that works as expected.

Given that my website only has one controller I would like to set things up such that the controller's name doesn't appear in the URL at all. So in other words, I would like to simply become And, of course, anywhere that my website references 'controller' (including URLs and URIs that are created with the CI helpers) should also be changed appropriately. I've tried fiddling with the .htaccess file and also with the routes but nothing seems to work as expected.

Can anyone point me in the right direction with some examples?

My .htaccess file looks like this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /mysite/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  ErrorDocument 404 /index.php

Even though my controller has several actions that I will continue to use ( seems far prettier than, I'm sure that hiding the controller from the URL must be possible - I just don't have a clue where to start.


Ok I think i have a solution for you. What worked for me is:

RewriteRule ^(.*)$ index.php/controller/$1 [L]

Let me know if that works for you.



We're writing a web app, which also contains some normal HTML website pages (about us, contact us, etc). We've put all these pages in a controller called "site" (because we want them out of the way from the web app). However, this results is URLs such as We would rather just have the URL be /about_us ... how can we achieve this?

I posted here because it seems to be a similar issue. Unlike the earlier post, we do have other controllers.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.