Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues in removing index.php in CodeIgniter 3

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

like image 558
Blessan Kurien Avatar asked May 28 '15 08:05

Blessan Kurien


1 Answers

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

like image 150
Mr. ED Avatar answered Oct 11 '22 03:10

Mr. ED