Home » Apache, Frameworks

Cleaner URLs in CodeIgniter

11 August 2009 No Comment

Here’s a quick tip to make cleaner looking URLs in CodeIgniter PHP framework. By default, if you have an application, the path of the application usually ends after index.php.  Using Apache RewriteEngine, you can make cleaner looking URLs. You can have something similar to mysite.com/cigniter/MyApplication instead of mysite.com/cigniter/index.php/MyApplication

  • Create a file named “.htaccess” inside your root CodeIgniter directory. It should look like the following:RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|robots\.txt)
    RewriteRule ^(.*)$ /[CODE IGNITER BASE]/index.php/$1 [L]where [CODE IGNITER BASE]  is the directory of your Code Igniter install. For instance, if you named your base install folder “cigniter”, the Rewrite Rule would look like:RewriteRule ^(.*)$ /cigniter/index.php/$1 [L]
  • If you get an error, make sure your Apache install allows for RewriteEngine in that particular folder. This is usually located in /etc/apache2/sites-enabled/YOURSITE The folder needs to have permissions of:AllowOverride AuthConfig
    Options +FollowSymlinksSee: http://www.whoopis.com/howtos/apache-rewrite.html
  • More info on CodeIgniter framework:
    http://codeigniter.com/

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.