How do I write a .htaccess file to make CodeIgniters URL routing work?

In your system/application/config/config.php, change

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

to

$config['index_page'] = "";

and in your .htaccess, add this:

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

Add your .htaccess file to the same directory where the system folder is located, so in your CodeIgniter root directory, you should have

  • system/
  • user_guide/
  • index.php
  • .htaccess
  • license.txt

Also, since you have multiple sites running on your server, you might want to have VirtualHosts. Add this to the last part your apache2.conf for each site that you have:

Listen *:11000
<VirtualHost *:11000>
     ServerAdmin [email protected]
     DocumentRoot "/var/www/cms"
     ServerName you-dummy.com
     <Directory "/var/www/cms">
          AllowOverride All
          Options +Indexes
          DirectoryIndex index.php
          Order allow,deny
          Allow from all
     </Directory>
     ErrorLog logs/cms_log
     CustomLog logs/cms_log common
</VirtualHost>

You may now access the site from http://localhost:11000/ and access the controller using http://localhost:11000/hello.

Leave a Comment