jigniter™

jQuery & CodeIgniter – Perfect combination for web application

Remove index.php from URL

9 comments

CodeIgniter is designed to be search-engine and human friendly. By default, index.php will be included in the URLs, but it can be easily removed using .htaccess file with some rules.

You will need to edit application/config/config.php file, at the following line to remove the index.php.

$config['index_page'] = "";

Using .htaccess with negative method

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

The example above shows how to process any HTTP requests as index.php except for those files or folders specified in the condition.

The approach before requires mod_rewrite in Apache server. However it is also possible to use rewrites in IIS (Internet Information Services) if you are on Windows.

You can also check the following resources: Wiki entry explaining how to use mod_rewrite, forum posts.

Troubleshooting

Troubleshooting #1 – Nothing happened

In case the changes do not work, you can try removing the uri_protocol setting in config.php. Look for:

$config['uri_protocol']	= "AUTO";

and change it to:

$config['uri_protocol']	= "";

Troubleshooting #2 – I am using XAMPP

Verify mod_rewrite is loaded when running Apache. Look at /apache/conf/httpd.conf for:

#LoadModule rewrite_module/mod_rewrite

and remove the first comment character:

LoadModule rewrite_module/mod_rewrite

Then restart Apache again.

No related posts.

Posted by admin

2009-07-25 at 2:28 pm

9 Responses to 'Remove index.php from URL'

Subscribe to comments with RSS or TrackBack to 'Remove index.php from URL'.

  1. Thanks for information. But these dont useful to me. I cant manage to remove index.php from urls. you can see my website. I ve even no clue why i couldt do it!

    Hope, you can help me.

    omerd

    2 Aug 09 at 3:47 am

  2. Hi omerd, thanks for your comment. Did you change your config file?
    Make sure you have an empty index_page value.
    $config['index_page'] = “”;

    admin

    2 Aug 09 at 8:23 pm

  3. yeah idid all the stuff. the last thing i did was changing this $config['uri_protocol'] = “AUTO”; to $config['uri_protocol'] = “”; and all other was set either. But still i cant use without index.php.

    Im pretty damn confused :S

    omerd

    3 Aug 09 at 2:46 pm

  4. i fpund my solution at last. In case of anyone with similar condition, i wanna write my solution:

    i make this .htaccess file

    ************************

    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

    ErrorDocument 404 /index.php

    *****************

    And other settings you can find in this page is also set. There is no index.php in urls. You can check my ws => http://www.oyuncek.com

    And i want to thank admin of durmus.net, because i found his answer on CodeIgniter Turkish GoogleGroups. And also thanks to admin of Jigniter.

    Cheers.
    omerd

    omerd

    4 Aug 09 at 9:58 am

  5. i think the system doesnt permit some htaccess commands. You can find full htaccess text here => http://groups.google.com/group/codeigniter-turkish/browse_thread/thread/6a1bd76037a4874b?hl=tr

    omerd

    4 Aug 09 at 9:59 am

  6. Hi omerd,
    Thanks for sharing. I am glad to know you was able to solve that problem.
    Look forward for staying in touch.

    admin

    5 Aug 09 at 9:04 am

  7. [...] In addition, if you are optimizing your application for search engines, then you may be interested in removing index.php from the default installation of CodeIgniter application. You can do that by reading this article. [...]

  8. If you run into a weird problem where no matter what you do you couldn’t go past your home page then it would be time to look the other side of the investigation. And that is to check your PHP and CI versions. It turned out that if you are using PHP 5.3 (blame Snow Leopard) then the earlier versions of CodeIgniter won’t play nice with PHP 5.3

    Instead you’d want to upgrade your CI version to 1.7.2 which is compatible with the PHP 5.3 version.

    Spent crazy amount of time today to figure this out finally :(

    DemoGeek

    23 Sep 09 at 11:29 pm

  9. Hi DemoGeek, thanks for the info.
    Hopefully you figured it out.

    admin

    24 Sep 09 at 8:45 am

Leave a Reply