Removing index.php From URL in CodeIgniter

In Code Ignitor by default all URLs except the default home contains "index.php" by default in the URL, For example http://localhost/index.php/class/function.

In order to make the URLs "cleaner", we have to remove "index.php" from the URL. This is done using the mod_rewrite module in apache to redirect all traffic to index.php/. The following code inside .htaccess does the redirection.

Code Igniter .htaccess Rules

# Code Igniter Htaccess Rules <IfModule mod_rewrite.c> RewriteEngine on # Rewrite URLs of the form 'x' to the form 'index.php/x'. RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php/$1 [L,QSA] </IfModule> We also have to configure the config.php "index_page" key so that it is blank. /* |-------------------------------------------------------------------------- | Index File |-------------------------------------------------------------------------- | | Typically this will be your index.php file, unless you've renamed it to | something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ $config['index_page'] = "";

.htaccess Does not work

If your htaccess does not work on localhost.
  • Goto your server configuration. In case of Apache 2, the conf would be in Installation Directory/conf/httpd.conf.
  • Look for the section Directory of your Document Root of your server <Directory "htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
  • Make sure AllowOverride is set to All and not None
  • Restart the server after making changes
  • And you're good to go

Solve No input file specified.

If you get "No input file specified." error on all pages, (such as on Dreamhost hosting), the error can be resolved by changing the Htaccess rules to

<IfModule mod_rewrite.c> RewriteEngine on # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?/$1 [L,QSA] </IfModule> :) 14 Mar, 2010
Comments (3)
  • Thank you!

    I use Dreamhost and your "Dreamhost" section fixed the issue of "no input file specified" just as you said it would. Thank you very much.

    By Unnecessary Force on 26 Jan, 2011
  • Wow, thank you

    I was ready to tear out my hair before I finally found your Dreamhost solution.

    By Becky on 12 Jun, 2010
  • Problem solved

    I'm new to Code Ignitor, and this post solve problems on my project.
    Thanks for the tips

    By Favey on 13 Apr, 2010
You may also like
On Facebook
Email Newsletter