Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2074

I can't remove the index.php from the CodeIgniter URL

I want to remove index.php from the path in CodeIgniter.

I tried to change the value of index_page in the config file as the following:

$config['index_page'] = '';

then I tried all these .htaccess :

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

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

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

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

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

But none of them has worked.

I also tried to to change the uri_protocol to this :

   $config['uri_protocol']  = 'ORIG_PATH_INFO';

But it's still doesn't work.

How can I solve this problem ?

Edit :

I tried this code to check if the mod_rewrite is enabled :

<?php
 if( ! function_exists('apache_get_modules') ){ phpinfo(); die; }
 $result = ' not available';
 if(in_array('mod_rewrite',apache_get_modules())) $result = 'available';

?>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p>

And I get this result :

Apache/2.2.22 (Ubuntu)

mod_rewrite not available

Upvotes: 1

Views: 1328

Answers (2)

Cody
Cody

Reputation: 915

I had the same issue.. then finally it worked with the following code

just follow these simple steps :

1. save the following code into .htaccss file..
2. put it in the main project folder (not the application folder)
3. rename the "/projectFolderName/" part on 3rd line of the code as your project folder name.

Then you are done. Refresh and see.

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /projectFolderName/ 

 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?/$1 [L]
</IfModule>

Upvotes: 3

user2936213
user2936213

Reputation: 1011

This works for me. Inyour .htaccess file write:

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

and in your config.php file :

$config['uri_protocol'] = 'AUTO';  

Make sure yout htaccess is in your root folder not in applications folder.

Upvotes: 0

Related Questions