bnelsonjax
bnelsonjax

Reputation: 321

codeigniter 404 error at root web site

I'm trying to setup codeigniter for our website.

if I want the main page to be http://example.com

and my folder structure looks like this:

public_html\
  application\
  common\
  system\

how do I setup codeigniter to show the page when going to http://example.com? I'm getting a 404 error when viewing it.

I edited config.php, but im not sure what to put for my base url.

my htaccess file:

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

my routes.php

$route['default_controller'] = "HomeController";
$route['404_override'] = '';

my HomeController.php

public function index()
{
    $this->load->model('HomeModel');
    $this->load->view('templates/header');
    $data['result'] = $this->HomeModel->function1();
    $this->load->view('index', $data);
    $this->load->view('templates/footer');

}

my HomeModel.php

<?php

class HomeModel extends CI_Model{

    public function index()
    {

    }

    public function function1()
    {
    $query = $this->db->get('work_orders');
        //return $query->result();
    return $query->result_array();

    }
}

Upvotes: 1

Views: 1098

Answers (3)

Furkat U.
Furkat U.

Reputation: 451

You can make base_url empty:

$config['base_url'] = '';

Try this working .htaccess conf:

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

IF nothing helps then hosting doesn't support mod_rewrite apache module

Upvotes: 0

Kees Sonnema
Kees Sonnema

Reputation: 5784

EDIT2:

Edit your default_controller from HomeController to homecontroller Like this:

$route['default_controller'] = "homecontroller";

and rename (if needed) your controller from HomeController.php to homecontroller.php and in your Controller itself call it Homecontroller.

Do the same for the model. call it homemodel.php (or home_model.php) in your directory and Call it Homemodel in your model itself.

Also clear your browser cache.


EDIT1:

Rename your model. I guess you called your model HomeModel.php. just call it home_model.php. this should fix your problem.


Your .htaccess file should look like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)

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

This is just copied from my server and it works great.

After then, change your default_controller to:

$route['default_controller'] = "the default controller";

and if public_html is a folder you created your index page should be:

$config['index_page'] = "public_html/";

otherwise leave it blank. (if it's your server's httpdocs)

should work :)

Upvotes: 0

GautamD31
GautamD31

Reputation: 28753

At your router.php in config folder there is an line

$route['default_controller'] = "your controller name";

add your controller that you want to display defaultly

Upvotes: 0

Related Questions