Abhinav Suryawanshi Abhinav Suryawanshi - 6 months ago 103
PHP Question

Codeigniter Routing for static pages home page working other routes not pages

When I access localhost:8080/ignite_me it shows me contents of home.php with header and footer but when I try localhost:8080/igniteme/test It gives me Apche 404 page and test.php exist in my views/pages where i have put my home.php

even localhost:8080/igniteme/home is not working but localhost:8080/igniteme shows content of home.php

routes.php

$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;


Pages.php

<?php
class Pages extends CI_Controller {

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

public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}

$data['title'] = ucfirst($page); // Capitalize the first letter



$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}


.htaccess

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


config.php

$config['base_url'] = 'http://localhost:8080/igniteme/';
$config['index_page'] = '';


I am unable to understand why home.php works with localhost:8080/ignite_me and why not with localhost:8080/igniteme/home or any other page is not working
I have copied .htaccess from some other stack overflow question it was not working even with default one.

here is link to my complete codeignite folder igniteme

Answer

I am using wamp I use 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 in main directory.

Also in wamp make sure YOU HAVE ENABLED APACHE MOD REWRITE

Scroll/click and go down the list to you find rewrite_module click on it then go and restart wamp.

enter image description here