I am in the threshold of exploring the CodeIgniter Framework, and I am facing a very basic problem here. I have a controller named pages, and it has a function called view.
Problem 1: Now when I type example.com/myfolder/ I do land to my page. But when I try something like example.com/myfolder/index.php/pages/view or example.com/myfolder/pages/view, it gives me a 404 Error.
Problem 2: I need to remove the index.php from the URL. Please rectify the .htaccess pasted below.
Controller
class Pages extends CI_Controller {
public function index() {
$this->view("home");
}
public function view($page = 'home') {
if (!file_exists('application/views/pages/' . $page . '.php')) {
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$data['company_name'] = "Demo Company 2013";
$this->load->view('templates/header', $data);
$this->load->view('pages/' . $page, $data);
$this->load->view('templates/footer', $data);
}
}
Routes
$route['default_controller'] = 'pages';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myfolder/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
config
$config['index_page'] = '';
$config['base_url'] = 'http://example.com/myfolder/';
Update
This might be important. I am running my site on a shared windows hosting, which is using IIS. So I suppose my .htaccess needs to be converted to web.config
.
UPDATE WEBCONFIG ADDED
Now, I have added the web.config from the link provided in one the answers. Thanks a lot; it was really helpful, but still I am getting the same old 404 Error. I tried changing the following my configuration file
$config['uri_protocol'] = 'QUERY_STRING';
But now I am getting errors about
<!doctyle HTML>
How can I fix this?