Php – Issues in removing index.php in CodeIgniter 3

codeigniterphp

I want to access my URL's without index.php in CodeIgniter. Here is my Blog controller

class Blog extends CI_Controller {

    public function index() {
        echo 'hello world';
    }

    public function about() {
        echo 'about page';
    }
}

Now I can access index via http://localhost/codeigniter/index.php/Blog, but I need to access it with this URL http://localhost/codeigniter/Blog.

NOTE

I removed index.php from config file
.htaccess file

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

Environment

Windows, XAMPP, PHP Version 5.6.3

Best Solution

How to removed index.php from url has been asked so many times, It is the same as what is for codeigniter 2 and 3.

For Xampp With Codeigniter Windows

Find application/config/config.php

Replace This

$config['base_url'] = "";

With This

$config['base_url'] = "your-project-url";

Replace This

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

With This

$config['index_page'] = ""

In main directory create file called .htaccess

I use code below works fine for me in xampp in windows. More htacces here

Options +FollowSymLinks
Options -Indexes

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

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

Note: make sure your controllers are like example Welcome.php instead of welcome.php also you might need to create new routes in your route.php if remove index.php

Related Question