punitjajodia
punitjajodia

Reputation: 92

Remove index.php from codeigniter url

I am a newbie at codeigniter. I have my codeigniter installed at localhost/path/learn_ci.

I have followed all the steps given in the codeigniter wiki. Here is my .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /learn_ci/index.php/$1 [L]
</IfModule>

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

I've also changed the config file as required. But when I try to access

I get this error

"The requested URL /learn_ci/index.php/welcome was not found on this server"

I have double checked...the mod_rewrite module in Apache is on.

The RewriteBase solution also didn't work. Am I doing something wrong??

Upvotes: 4

Views: 8334

Answers (6)

Dibyendu Mitra Roy
Dibyendu Mitra Roy

Reputation: 1665

You can do the following:

First in config.php file set

$config['index_page'] = '';

Next, create a .htaccess file in the codeigniter root folder and add the following content:

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

Save the file. It should work.

Upvotes: 1

newday
newday

Reputation: 3878

I thought to add my answere. My project base url is http://localhost/newproject/ I included htacess file in the newproject folder.

here is the code.

RewriteEngine on

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

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

then I change config file.

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

and every thing started to work. now nomore index.php file.

Upvotes: 0

Jordan Patterson
Jordan Patterson

Reputation: 606

As others have said, make sure that AllowOverride is set to All in your apache config or your virtual host file. Given the path that you have codeigniter setup in, your htaccess should look like this:

RewriteEngine On
RewriteBase /path/learn_ci

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

Also, remember that any assets you are using (img, css, js, etc) are referenced either with the base_url() function or using relative paths. The root of your project is going to be /path/learn_ci.

I find that it is easier to create a virtual host and add an entry to my hosts file locally. This mimics real life much better.

Upvotes: 2

greenLizard
greenLizard

Reputation: 2346

Check your apache config, it should be something like :

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

Try:

RewriteEngine On
RewriteBase /

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

Upvotes: 1

Laurence
Laurence

Reputation: 60068

You place the htaccess file in your root public_html folder in the same directory as index.php

Then remove /learn_ci from your htaccess file, just make it /index.php/$1

Upvotes: 0

Related Questions