The default controller does not load after redirection

I have a multi-user codeigniter installation where I have code that I can serve on sites with such links

site.com/sites/sitename/controller/function/vars site.com/controller/function/vars/

subdom.site.com/controller/function/vars

the problem is that when routing

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

I get working links like

site.com/sites/sitename/controller/function/vars site.com/controller/function/vars

In theory, when I go to

www.site.com/sites/sitename/

the controller does not boot by default.

I made config.php so that regarding the link structure when I visit the 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

$ configuration ['base_url'] = "http://site.com/";

for the second case, the controller loads fine by default. For the case of a sub-site, not /

I get only 404

What to do?

UPDATE 2:

I have a multi-threaded installation.

When a user goes to www.site.com/sites/site_name

then application folder

Loading

/ root_folder / usersites / site_name.

When a user is sent only to the site .com / controller / function / var1 / var2

default application folder which

/ root_folder / application uploaded

when the user goes to the sub1.site.com application folder

/ root_folder / domains / sub1_site_com uploaded

So, when I enter the address bar

http://site.com/sites/site_name

it should be like a URI. and should load the 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;
+3
3
$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';
                        }

. , . . .

0

, , :

.htaccess (.. , system). :

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

. " index.php" : http://codeigniter.com/user_guide/general/urls.html .

, route, , , www.site.com, www.site.com/sites/content.

url www.site.com/sites/sitename/content/, sites - , sitename , content sitename - , , , .

, (), .


UPDATE:

1: $config['base_url'] , .

2: , ().

,

www.site.com/sites/sitename/

.

CI:

CodeIgniter , URI , , URL- . , /config/routes.php :

, , default_controller , URI. : , URL- www.site.com, ( - . ).

, , .

routes.php:

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

:

P2aUt.png

, . . ( content.php ).

www.site.com/sites/site1 (content) application/controllers/site1/content.php index .

site1, URL- : www.site.com/sites/site1/content/otherFunction.

, .

+1

, , - "sitename", . , site.com/sites/my-site/, my-site .

/.

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

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

, , sitename .

+1
source

Source: https://habr.com/ru/post/1756794/


All Articles