8

I'm trying to remove the index.php from my CI urls, but having followed the instructions it doesn't seem to be working.

I have a codeigniter installation running in a subdirectory. There is a default controller set in the routes config called main, and another controller called 'create'. The default runs fine, but going to /create returns a 324 error saying No Data Received. My htaccess looks like this:

<IfModule mod_rewrite.c>

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]

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>
Robin
  • 3,533
  • 4
  • 18
  • 8

5 Answers5

27

This should be enough:

<IfModule mod_rewrite.c>
RewriteEngine On

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
scc
  • 10,342
  • 10
  • 51
  • 65
8

This is what I use. My CodeIgniter also runs in a subdir.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
  • 4
    I've been looking for the right mod_rewrite for hours and this is the one that finally worked for me! All I had to do was change `ci/` to `mysubfolder/` – Kevin Beal Jan 01 '13 at 06:43
6

.htaccess add:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Go into application/config/config.php and clear the index page config value:

// Old

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

// New

$config['index_page'] = "";

Solved My problem hope others too... :)

jack7en
  • 151
  • 1
  • 6
  • i trying the code from codeigniter user guide and didn't work but now its work like a magic thanks sir – Belajar Sep 12 '13 at 04:30
1

Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":

sudo a2enmod rewrite

You need to restart the webserver to apply the changes:

sudo service apache2 restart

Then folow Sofia's answer.

Florin
  • 5,781
  • 2
  • 20
  • 30
0

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

for ubuntu