开发者

CI: Controllers in subfolder - removing subfolder from url

开发者 https://www.devze.com 2023-03-14 12:20 出处:网络
I want to group my controllers, views and models into public/ and members/ subfolders. But for the public stuff, I don\'t want /public/ to show in the URL, so:

I want to group my controllers, views and models into public/ and members/ subfolders.

But for the public stuff, I don't want /public/ to show in the URL, so:

http://mysite.com/ & http://mysite.com/section/

should point to: /public/home & public/section/

How should I change 开发者_运维技巧routes.php to accommodate this?


(I'm fine with members/ stuff having members/ in the url)


To make http://mysite.com/ point to /public/home you will need to mark public/home as your default controller. You will also need to add a specific route to make http://mysite.com/section point to /public/section. Try this (the regex is a little dubious in my opinion, but may do what you want):

$route['default_controller'] = "public/home";
$route['section/(.*?)'] = "public/section/$1";


Kindly see if this works for you:

$route['section'] = "public/section";

Your index page would remain as "public/index.php"


You don't need to add routes for every controller.

This works for me:

$route['members'] = 'members'; // route members to members
$route['members/(.*?)'] = 'members/$1'; // route members/... to members/...
$route['(.*?)'] = 'public/$1'; // route anything but above lines to public/...

The first two lines are intentionally redundant to protect 'members' segment from being routed to 'public'. And the third line does the magic.

0

精彩评论

暂无评论...
验证码 换一张
取 消