Rui
Rui

Reputation: 5920

CodeIgniter remove index.php from url

I'm having some trouble removing index.php from my CI app urls. Followed the official documentation here but apparently something's missing yet. I setup a CI app and placed it on /var/www/test on my server, where test is a symlink pointing to /home/user/websites/test. Everything is working fine if I do http://myIp/test/index.php/welcome, but working if I do http://myIp/test/welcome. I included an .htaccess in my test folder, containing the following:

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

and also played with RewriteBase property without success. What am I doing wrong or missing?

Upvotes: 0

Views: 666

Answers (5)

Sally
Sally

Reputation: 31

put the following in .htaccess

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

<Files "index.php">
AcceptPathInfo On
</Files>

put this file near to index.php out of application and system folders and near to them don't forget to write $config['index_page'] = ''; instead of $config['index_page'] = 'index.php';

Upvotes: 1

Zeeshan
Zeeshan

Reputation: 801

If i have got your question right you want to make your links working & remove 'index.php' from URL.Follow following steps & let me know if that solves your issue.

1) Remove 'index.php' from config.php which is located in config directory make it look like this $config['index_page'] = '';

2) Add this to .htaccess file

DirectoryIndex index.php
RewriteEngine on

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

If you have any doubts or issues let me know.Hope it helps.

Best Regards, Zeeshan.

Upvotes: 0

Sherif
Sherif

Reputation: 11942

Your rewrite rule is incorrect (or faulty at best). It should be as follows

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

The [L] flag in the RewriteRule indicates to apache that no further rules should be processed and that the rule should be applied immediately. See the apache documentation about the L flag for more information on this. In your case this is important due to the fact that you are using symlinks and .htaccess file instead of applying the rule to your vhost file directly, which is highly recommended given this case as well as the case that .htaccess is slow.

Upvotes: 0

tcj
tcj

Reputation: 1675

Try this one :

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

Upvotes: 0

GluePear
GluePear

Reputation: 7735

Open application/config/config.php, and change

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

to

$config['index_page'] = '';

Upvotes: 0

Related Questions