I just recently started learning CodeIgniter and trying to setup my project in this structure:
Specification
Apache/2.4.27 (Win64) PHP/5.6.31.
Server: WAMP Server 3 Localhost setup
CodeIgniter 3.1.2
Directorywww/CI/firstci/******
So using this directory structure will give me a 404 error when I navigate to www/CI/firstci/
404 Page Not Found The page you requested was not found.
If i put my CodeIgniter higher up the root like this
Directorywww/firstci/******
It will work when I navigate to www/firstci/
and it will direct me to a welcome page.
So my question is how do I fix this routing/path problem? If possible explain why CodeIgniter behaves like this too?
Ok i have found out that after i changed:
routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
TO
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Add a controller file called Pages.php
class Pages extends CI_Controller {
public function view($page = 'home') {
if (!file_exists(APPPATH.'views/pages/'.$page.'.php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/header');
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer');
}
}
Also added .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
And added the relevant files to view folder organizing it to this structure:
templates/header
pages/'.$page, $data
templates/footer
It now works and is able to direct me to any php page
Here ate some basic step to run CI Setup.
config.php
index.php
file. here is the documentation link