Nidheesh N Namboodhiri
Nidheesh N Namboodhiri

Reputation: 199

How to remove index.php in a codeigniter site to help seo

I want remove "index.php" from my url

http://localhost/simpleblog/index.php/blogger/NewBlogs

I need it as

http://localhost/simpleblog/blogger/NewBlogs

here shows my Controller Code

class Blogger extends CI_Controller {

    public function NewBlogs()
    {
        $this->load->helper('url');
        $this->layout="Yes"; //<-- add this*/
       /* $this->load->view('welcome_message');*/
        $this->load->view('Pages/SecondPage');
    }
}

Default Controller

public function index()
{
    $this->load->helper('url');
    $this->layout="Yes"; //<-- add this*/
   /* $this->load->view('welcome_message');*/
    $this->load->view('Pages/MainPage');
}

How to remove index.php ?

Upvotes: 1

Views: 503

Answers (4)

Nikesh barod
Nikesh barod

Reputation: 46

You should enter this code in your .htaccess file

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

And replace this code in config.php file

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

           To

$config['index_page'] = '';

Upvotes: 0

Shareque
Shareque

Reputation: 361

Removing the index.php file

  • First, go to /application/config/config.php find

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

replace with

$config['index_page'] = '';
  • Second, just create a .htaccess file at the root directory of your project

i.e /.htaccess

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

save your file with name .htaccess

Upvotes: 0

phphelper
phphelper

Reputation: 1

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

Upvotes: 0

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

Removing the index.php file

By default, the index.php file will be included in your URLs:

example.com/index.php/news/article/my_article

You can easily remove this file by using a .htaccessfile with some simple rules.

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

See Documentation

Upvotes: 1

Related Questions