Reputation: 3935
I have created a Home page controller with a Page method so that it can load inner page views. So I simply pass the Page name as an argument to Page method and it loads that specific view.
E.g.
http://www.mywebsite.com/home/page/copyright
So here 1. home is controller 2. page is method 3. copyright is the parameter passed to page() method
So the home age loads simply using this URL
http://www.mywebsite.com/home/
and inner pages load using this url pattern
http://www.mywebsite.com/home/page/copyright
Now I want to load inner pages so that suppose I use this URL
http://www.mywebsite.com/copyright
it should load the page from
http://www.mywebsite.com/home/page/copyright
How can I do this using Codeigniter Route method or by using .htaccess file ?
Thanks in advance.
Upvotes: 0
Views: 2041
Reputation: 1429
On your application/config/routes.php :
$route['copyright'] = 'home/page/copyright';
Even better:
$route['(:any)'] = 'home/page/$1';
So if you navigate to http://www.domain.com/copyright it routes to home/page/copyright
If you navifate to http://www.domains.com/anything it routes to home/page/anything
EDIT to catch any route
Although in this case you have to "catch" pages that you don t route like:
function page($section = ''){
switch($section){
case 'contact':
//display contact form
break;
case 'copyright':
//display copyright
break;
default:
//404 error
break;
}
}
Upvotes: 1