I have a codeigniter multistie install where I have such code that I can serve sites with such links
site.com/sites/sitename/controller/function/vars site.com/controller/function/vars/
subdom.site.com/controller/function/vars
the challange is that , whith the routing
$route['sites/([^/]+)/(.*)'] = '$2';
$route['default_controller'] = "content";
I get working the links like
site.com/sites/sitename/controller/function/vars site.com/controller/function/vars
By idea when I go to
www.site.com/sites/sitename/
the default controller is not loading.
I made the config.php so that regarding the link structure, when I visit link
site.com/sites/sitename/controller/function/vars
then
$config['base_url']="http://site.com/sites/sitename";
if I go to
site.com/controller/function/vars
then
$config['base_url']="http://site.com/";
for the second case the default controller loads perfectly. For the subsite case not/
I get just 404
What to do?
UPDATE 2:
I have a multifolder setup.
When user goes to www.site.com/sites/site_name
then a folder of application
/root_folder/usersites/site_name is loaded.
When user goes just site.com/controller/function/var1/var2
a default application folder which is
/root_folder/application is loaded
when user goes to sub1.site.com application folder
/root_folder/domains/sub1_site_com is loaded
So when I enter in address bar
http://site.com/sites/site_name
it should be like no URI. and should load default 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;
What you appear to be doing is looking for a controller with the 'sitename' you are passing through. So if you navigate to site.com/sites/my-site/ you route tells it to look for a controller called my-site and run the index method.
The value of the route should be a path to an actual controller / method pair.
$route['sites/([^/]+)/(.*)'] = '$2';
should be
$route['sites/([^/]+)/(.*)'] = 'sites/index/$1/$2';
This is assuming it's the index method that accepts the sitename as it's first parameter in your sites controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With