views:

117

answers:

3

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;
+1  A: 

It's not totally clear what you're asking, but heres a shot:

You need to create an .htaccess file in the root of your site (i.e. in the same folder that your system folder is in). In that file:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

See the "Remove the index.php file" section of this page: http://codeigniter.com/user_guide/general/urls.html for more info.

Also, the route that you're using would make it so that when you go to www.site.com, you will see www.site.com/sites/content.

With the url www.site.com/sites/sitename/content/, sites is your controller, sitename the method or function, and content would be considered a parameter to the sitename function -- this won't work like it seems like you want, but I can't be sure without seeing your controller.

Maybe edit your question and add your controller(s), and we can be of more assistance.


UPDATE:

1: $config['base_url'] has nothing to do with routing or which controller is being used, so this is making your question harder to understand.

2: It isn't clear what you are trying to accomplish (sorry).

By idea when I go to

www.site.com/sites/sitename/

the default controller is not loading.

According to the CI user guide:

CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:

So, what this means is that the default_controller is used only when there is no URI present. In other words: the default controller only applies when the URL is www.site.com, and in no other case will it be used (unless you are using sub-folders in the controllers folder -- see below).

If you trying to make it so that each of your sites has its' own controller, you could use subfolders in your controller folder.

In routes.php:

$route['sites/(:any)'] = "$1";
$route['default_controller'] = "content";

Then your folder structure:

So you have your controller folder. In it, create a folder for each site. In each of those controllers create your default controller (named content.php in the above image).

With this setup, www.site.com/sites/site1 will call the default controller (content) from application/controllers/site1/content.php and show the index function of that controller.

If you then want to call other functions of the site1 controller, the URL would look like: www.site.com/sites/site1/content/otherFunction.

Hope this helps.

stormdrain
stromdrain thanks for answer, but I know how to remove index.php and make nice links. i have edited the question. Now is more clear?
DR.GEWA
@DR.GEWA : please see the "UPDATE" section of my answer above.
stormdrain
the routing you suggest also doesn't work.... 404...
DR.GEWA
so, any idea? what can be done?
DR.GEWA
@DR.GEWA : does this help: http://codeigniter.com/user_guide/general/managing_apps.html ?
stormdrain
no. because I have problem with routing, not with loading application folders. What I need just in routing 2 roules. 1. In case of url like www.multi.com/sites/siteX/ ->>>>>> /content/index/2. in case of url www.multi.com/sites/siteX/controller or www.multi.com/sites/siteX/controller/method ->>>>controller/method/ passing also variables.
DR.GEWA
+1  A: 

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.

WeeJames
this routing will not work, as I don't have any sites.php controller in my application folder
DR.GEWA
A: 
$uri_string=$_SERVER['REQUEST_URI'];
                    $way=explode('/',$uri_string);


                       /// print_r($way);

//echo $way[3];
                        if($way[1]=="sites" and strlen($way[2])>2 and strlen($way[3])<1){


                            echo "JAJA ";


$route['sites/:any'] = "content/show_page/home";
                        }
                        else{



                           $route['sites/([^/]+)/(.*)'] = '$2';
                        }

this was solution. thanks all who answered. thanks stormdrain. you pointed me to a write direction in your routing example. Thanks

DR.GEWA