1

I am tried to remove index.php in Codeigniter HMVC. But I Could not complete with the following code.

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

I placed .htaccess file in root directory and removed index.php from config file. Still I'm facing the same problem.

Pradeep
  • 9,667
  • 13
  • 27
  • 34

4 Answers4

2

in your config.php file put

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

Then in .htaccess file put

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Now, check your url removing index.php. It will work.

disha
  • 123
  • 11
1

Please follow some step:

  1. goto application/config/config.php : replace $config['index_page'] = 'index.php'; to $config['index_page'] = ''; and $config['uri_protocol'] = 'REQUEST_URI'; to $config['uri_protocol'] = 'AUTO';

  2. enable rewrite mode by
    sudo a2enmod rewrite then service apache2 restart

  3. if you'd like, you can use the following .htaccess file.

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

Vijay Sharma
  • 833
  • 8
  • 15
0

Simply create one new file .htaccess.

And past it the below code into the .htaccess file.

Then go into the project folder follow the path application->config->config.php

into the config.php file

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


RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

// into the above line example is the project name, you have to replace the example to your project name

0
RewriteBase /g-pos  /// Your htdocs
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
  • 2
    You should include some commentary, this post is over 3 years old, OP has probably moved on so they are not likely to come back and validate or accept your solution. This answer is also very similar to the existing answer with the most votes, so tell us, what makes this solution superior, what does it do that the others have missed? – Chris Schaller Sep 14 '20 at 11:04