我有一个 codeigniter multistie 安装,我有这样的代码,我可以用这样的链接为网站提供服务
site.com/sites/sitename/controller/function/vars site.com/controller/function/vars/
subdom.site.com/controller/function/vars
挑战在于,路由
$route['sites/([^/]+)/(.*)'] = '$2';
$route['default_controller'] = "content";
我开始处理像
这样的链接site.com/sites/sitename/controller/function/vars site.com/controller/function/vars
我去的时候的想法
www.site.com/sites/sitename/
默认 Controller 未加载。
我制作了 config.php 以便关于链接结构,当我访问链接时
site.com/sites/sitename/controller/function/vars
然后
$config['base_url']="http://site.com/sites/sitename";
如果我去
site.com/controller/function/vars
然后
$config['base_url']="http://site.com/";
对于第二种情况,默认 Controller 完美加载。对于子站点情况不/
我只得到 404
怎么办?
更新 2:
我有一个多文件夹设置。
当用户访问 www.site.com/sites/site_name 时
然后是一个应用文件夹
/root_folder/usersites/site_name 已加载。
当用户访问 site.com/controller/function/var1/var2
一个默认的应用程序文件夹是
/root_folder/应用程序已加载
当用户转到 sub1.site.com 应用程序文件夹时
/root_folder/domains/sub1_site_com 已加载
所以当我在地址栏中输入
http://site.com/sites/site_name
它应该像没有 URI。并且应该加载默认 Controller 。
// Application folder loading code
$myApp = '';
if($_SERVER['SERVER_ADDR']=='127.0.0.1'){
$main_url='site.com';
}
else{
$main_url='site1.com';
}
//echo $main_url;
switch($_SERVER['HTTP_HOST'])
{
case $main_url;
$uri_string=$_SERVER['REQUEST_URI'];
$link_way=explode('/',$uri_string);
if(strlen($uri_string)>6 and $link_way[1]=='sites' ){
//print_r($link_way);
//var_dump($link_way);
//checking if the link goes to usersites and sitename is bigger and =5
if($link_way[1]=='sites' and strlen($link_way[2])>=5){
$myApp='sites/usersites/'.$link_way[2];
define('SITE_ALIAS','1|'.$link_way[2]);
}
elseif($link_way[1]=='sites' and strlen($link_way[2])<5){
exit('Username should be more than 4 chars');
}
}
else{
define('SITE_ALIAS','0|'.str_replace('.','_',$_SERVER['HTTP_HOST']));
$myApp = 'application';
}
break;
default:
$myApp = str_replace('.','_',$_SERVER['HTTP_HOST']);
$myApp=str_replace('www_','',$myApp);
define('SITE_ALIAS','2|'.$myApp);
$myApp='sites/domains/'.$myApp;
}
$application_folder = $myApp;
最佳答案
您似乎在寻找具有您正在通过的“站点名称”的 Controller 。因此,如果您导航到 site.com/sites/my-site/
,您的路由会告诉它查找名为 my-site 的 Controller 并运行索引方法。
路由的值应该是实际 Controller /方法对的路径。
$route['sites/([^/]+)/(.*)'] = '$2';
应该是
$route['sites/([^/]+)/(.*)'] = 'sites/index/$1/$2';
这是假设它是接受站点名称作为站点 Controller 中的第一个参数的索引方法。
关于codeigniter - 重新路由后未加载默认 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3346858/