Codeigniter Setting Homepage ( Default Controller ) Codeigniter Setting Homepage ( Default Controller ) codeigniter codeigniter

Codeigniter Setting Homepage ( Default Controller )


application/config/routes.php

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


The problem is that there's no URI segment when you visit www.mywebsite.com. You can try setting the default value as:

$this->uri->segment(1 , 'blog')


Your code

// Fetch the page template$this->data['page'] = $this->page_m->get_by(array('slug' => (string) $this->uri->segment(1)), TRUE);count($this->data['page']) || show_404(current_url());

the uri segment code

$this->uri->segment(1)

is looking first url segment, when you browse your site like www.yousite.come/blog it will work find but when you do www.yoursite.com 1st uri segment is missing so it will return false , so i will show 404 page.

Solution :You can just add the second parameter to the function like

$this->uri->segment(1,'blog');

now if the first url segment is missing it will not return false,it will return the default vlaue 'blog'

For more information about this you can see codeingitor documentation