0

I know there are so many posts concering that problem. I tried everything, but without success.

I use xampp v3.2.2 on my windows 10 machine. In my htdocs I got a project called mysite. In there I have codeigniter 3.0.3.

config.php

$config['base_url'] = 'http://localhost/mysite/';

$config['index_page'] = '';

routes.php

$route['default_controller'] = 'CI_home';

Controller CI_home.php:

class CI_home extends CI_Controller{

    function __construct() {
        parent::__construct();
    }

    public function index($lang = ''){
        $this->load->helper('url');
        $this->load->helper('language');
        $this->lang->load($lang, $lang);
        $this->load->view('view_home');
    }
}

When I call http://localhost/mysite, the page is shown correctly.

The problem is, when I try to http://localhost/mysite/en or http://localhost/mysite/index/en I received a 404 from xampp.

But if I try http://localhost/mysite/index.php/CI_home/index/en it works fine.

What I am doing wrong? How can I remove the "CI_home/index"?

http://localhost/mysite/.htaccess:

.htaccess

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

I already checked if the mod_rewrite is enabled.

Please help me!

Thanks in advance, yab86

5
  • Add to your route.php $route['(:any)'] = 'CI_home/$1'; Commented Jan 20, 2016 at 22:16
  • Thank you MAZux. I tried, but nothing changed. Commented Jan 20, 2016 at 22:19
  • Try to add the index method also, try: $route['(:any)'] = 'CI_home/index/$1'; Commented Jan 20, 2016 at 22:30
  • Which one are you using wamp, xampp, lamp etc Commented Jan 20, 2016 at 23:18
  • Possible duplicate of How to remove "index.php" in codeigniter's path Commented Jan 21, 2016 at 5:21

1 Answer 1

3

Try this htaccess below

Options +FollowSymLinks
Options -Indexes
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]

Make sure htaccess in your main directory.

Then set your base url

$config['base_url'] = 'http://localhost/yourproject/';

Then remove index.php

$config['index_page'] = '';

Note: Codeigniter 3 versions are case sensitive. Make sure only the first letter upper case of class and file name.

<?php

class Ci_home extends CI_Controller {

    public function __construct() {
         parent::__construct();
    }

     public function index($lang = '') {
       $this->load->helper('url');
       $this->load->helper('language');
       $this->lang->load($lang, $lang);
       $this->load->view('view_home');
     }
}

Then make sure file name is Ci_home.php

Then your default route should be

When using default controller make sure is the same name as the controller you choose.

URI Routing

$route['default_controller'] = 'ci_home';

$route['(:any)'] = 'ci_home/index/$1';
Sign up to request clarification or add additional context in comments.

1 Comment

It was the problem with letter upper case. Thank you wolfgang1983!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.