[英]Set route in different directories Codeigniter
Divided controllers into folders, site in site folder, admin in admin folder (inside controllers). 将控制器分为文件夹,站点文件夹中的站点,管理员文件夹中的admin(内部控制器)。
But I can not access the controllers without putting the base of the same folder url, example: 但是我不能在没有放置相同文件夹URL的基础的情况下访问控制器,例如:
I want to access like this: http://localhost/gabriel/projeto/about
我想这样访问:
http://localhost/gabriel/projeto/about
But just so I can: http://localhost/gabriel/projeto/site/about
但是我可以这样:
http://localhost/gabriel/projeto/site/about
File 'htaccess' this so: 文件“ htaccess”是这样的:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
'base_url' this so: 'base_url'这样:
$config['base_url'] = 'http://localhost/gabriel/projeto/';
File 'routes' this so: 归档“路由”,这样:
$route['default_controller'] = "site/index/";
$route['404_override'] = '';
$route['admin'] = "admin/login";
Already tried modifying the .htaccess but no result. 已经尝试修改.htaccess,但没有结果。 Inserting another line in the file 'routes':
在文件“ routes”中插入另一行:
$route['(:any)'] = "site/$1";
But putting that line it conflicts with the route ends and the Admin can receive only one parameter in Url. 但是,把那条线与路线末端冲突,管理员只能在网址中接收一个参数。
How can I solve this problem? 我怎么解决这个问题? make dynamic route...
制作动态路线...
I'm not 100% sure this is what you're asking, but try setting the base_url in the config/config.php file 我不是100%确定这就是您要的内容,但是请尝试在config / config.php文件中设置base_url
$config['base_url'] = 'http://localhost/gabriel/projeto/';
or set to whatever you want your site root to be 或设置为您希望站点根目录为
将此添加到您的routes.php中..将其置于所有其他$ route变量之上...
$route['projeto/about'] = 'projeto/site/about';
Solved my problem as well: 也解决了我的问题:
$route['admin/(.*)'] = "admin/$1";
$route['(.*)'] = "site/$1";
Now this dynamic route 现在,这条动态路线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.