简体   繁体   English

Codeigniter子域重定向-控制器

[英]Codeigniter Subdomain Redirect - Controller

I want to be directed to the controller that I specified when I logged in with the subdomain. 我想定向到使用子域登录时指定的控制器。

for example 例如

www.mysite.com -> mysite.com/main_controller

abc.mysite.com -> mysite.com/sub_controller
stack.mysite.com -> mysite.com/sub_controller
test.mysite.com -> mysite.com/sub_controller

www.mysite.com/other_controller -> mysite.com/other_controller

How can I direct subdomains like this? 我该如何指导子域名?

Thank you. 谢谢。

You don't need to play with htaccess, we can do some tricks. 您不需要玩htaccess,我们可以做一些技巧。 find below. 在下面找到。

Create new folder inside the root folder (where you have installed the application and system folders). 在根文件夹(已安装应用程序系统文件夹的位置)内创建新文件夹。

Here i'm calling subdomain is the new folder for this case. 在这里,我将subdomain称为这种情况下的新文件夹。 So your root directory should like this. 所以您的根目录应该是这样的。

/application
/system
/subdomain
/.htaccess
/index.php
/..

Then copy /index.php & paste it inside the /subdomain directory and change sub settings like below 然后复制/index.php并将其粘贴到/subdomain目录中,并更改子设置,如下所示

$system_path = '../system';
$application_folder = '../application';
$view_folder = '../application/views';

then, add this code in your /application/config/routes.php 然后,将此代码添加到您的/application/config/routes.php

if($_SERVER['HTTP_HOST'] == 'mysite.com'){
    $route['default_controller'] = 'main_controller';   
}else{
    $route['default_controller'] = 'sub_controller'; 
}

-OR- -要么-

switch ( $_SERVER['HTTP_HOST'] ) {
    case 'abc.mysite.com':
        $route['default_controller'] = "sub_controller";
    break;
    case 'stack.mysite.com':
    case 'test.mysite.com':
        $route['default_controller'] = "sub_controller_2";
    break;
    default:
        $route['default_controller'] = 'main_controller';
}

finally, point your subdomain (ex. abc.mysite.com) to /subdomain directory 最后,将您的subdomain (例如abc.mysite.com)指向/subdomain目录

you do it with other method too, if you need refer following links. 如果您需要参考以下链接,也可以使用其他方法进行操作。 https://code.tutsplus.com/tutorials/basecamp-style-subdomains-with-codeigniter--net-16330 http://asvignesh.in/dynamic-subdomain-in-codeigniter/ https://code.tutsplus.com/tutorials/basecamp-style-subdomains-with-codeigniter--net-16330 http://asvignesh.in/dynamic-subdomain-in-codeigniter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM