swl1020
swl1020

Reputation: 823

Removing index.php from a Codeigniter website

So, I've spend hours on this. I cannot figure it out. I've read several message boards and have not got it working.

Here's what I have done:

1) Added a file called ".htaccess" to the folder "/www/site_name". this file contains the following:

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

2) changed

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

to

$config['index_page'] = '';

3) went through several httpd.conf files changing every possible combination of the lines:

AllowOverride None

to

AllowOverride All

4) enabled the rewrite_module

This is driving me absolutely mad. I've spent literally hours on this.

EDIT: Maybe i'm not setting the right AllowOverride to all. Which one is the right one?

EDIT: I got it working. Thank you to the chosen answer for the help

Upvotes: 0

Views: 368

Answers (1)

Ben Swinburne
Ben Swinburne

Reputation: 26467

Below is the .htaccess file which I use on my codeigniter installations. Perhaps you could try it out in an attempt to rule out the .htaccess file? If this works then we can add in your other rules if they're really necessary for your situation?

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /

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

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

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?baseurl=$1 [QSA,L]
</IfModule>

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

The lines below bulk cater for your requirement to allow directories like /images/ and files such as robots.txt etc. If the file or folder exists it wont be rewritten. The application and system directories are protected by the other rules though.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Upvotes: 1

Related Questions