Thursday, November 5, 2015

How to remove index.php from codeigniter in Raspbian....... 2 different solution!

In application/config/config.php change:
$config['index_page'] = 'index.php';
to:
$config['index_page'] = '';
Step 1 :
Add this in htaccess file
<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>
Step 2 :
Remove index.php in codeigniter config
$config['base_url'] = ''; 
$config['index_page'] = '';
Step 3 :
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
for www folder
Step 4 :
Enabled apache mod rewrite (Command)
sudo a2enmod rewrite
Step 5 :
Restart Apache (Command)
sudo /etc/init.d/apache2 restart
-------------------------------------------------------------------------------------------------------
Solution 2:
There are 3 steps to remove index.php
1.Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Make .htacces file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
3.Enable rewrite mode (if your rewrite mode is not enabled)
i. First, initiate it with the following command:
a2enmod rewrite
ii. Edit the file /etc/apache2/sites-enabled/000-default
change All AllowOverride None to AllowOverride All.
iii. Restart your server with the following command:
sudo /etc/init.d/apache2 restart

No comments:

Post a Comment