views:

2032

answers:

5

How do I remove the "index.php" sticking out in every path in codeigniter somewhere in the center? I want clean non index.php-fied URLs?

+1  A: 

Use mod_rewrite as instructed in this tutorial from the CI wiki.

Ben S
A: 

This is an .htaccess for one of my CI projects:

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

The last line should give you what you need, though you may or may not need '/projectFolder' depending on how your folder structure is set up. Good luck!

mrinject
+2  A: 

Have a look in the system\application\config\config.php file, there is a variable named 'index_page'

It should look like this

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

change it to

$config['index_page'] = "";

Then as mentioned you need to add a rewrite rule to the .htaccess file

Re0sless
+4  A: 

If you are using Apache place a .htaccess file in your root web directory containing the following:

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Another good version is located here:

http://snipplr.com/view/5966/codeigniter-htaccess/

Sean Vieira
+1 for the link! Although had to tweak around a bit. got it with this --> RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L]
OrangeRind
A: 

Another solution I found is:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /codeigniter
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ /index.php/$1 [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|images|robots\.txt|css)
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

Then, in the file system/applications/config/config.php...

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

Remove the index.php and leave the file like this:

$config['index_page'] = "";
xterico