CodeIgniter Forums

Full Version: hao can i routing subdomain?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hao can i routing subdomain?  
Not from CodeIgniter. You can route only controllers of the domain/subdomain, where your system is installed or from where it is accessed.

Read URI Routing section in the documentation.

But maybe with a .htaccess file or by changing the server configuration it could be achievable, but it is just a hypotesis. Tell us, if you will find a solution.
Some things are simpler than they seem ...

Code:
// application/config/routes.php
switch ($_SERVER['HTTP_HOST'])
{
    case 'sub.domain.tld':
        // your sub.domain.tld routes here
        break;
    case 'default.domain.tld':
    default:
        // your default domain routes here
        break;
}
(09-23-2015, 05:00 AM)Narf Wrote: [ -> ]Some things are simpler than they seem ...


Code:
// application/config/routes.php
switch ($_SERVER['HTTP_HOST'])
{
   case 'sub.domain.tld':
       // your sub.domain.tld routes here
       break;
   case 'default.domain.tld':
   default:
       // your default domain routes here
       break;
}

Wouldn't this only work if your subdomain is pointing to the same root directory as your main domain?
(09-23-2015, 05:13 AM)Martin7483 Wrote: [ -> ]
(09-23-2015, 05:00 AM)Narf Wrote: [ -> ]Some things are simpler than they seem ...



Code:
// application/config/routes.php
switch ($_SERVER['HTTP_HOST'])
{
   case 'sub.domain.tld':
       // your sub.domain.tld routes here
       break;
   case 'default.domain.tld':
   default:
       // your default domain routes here
       break;
}

Wouldn't this only work if your subdomain is pointing to the same root directory as your main domain?

Yes, but how else do you expect to be able to have domain-based routing within CI?
(09-23-2015, 05:19 AM)Narf Wrote: [ -> ]
(09-23-2015, 05:13 AM)Martin7483 Wrote: [ -> ]
(09-23-2015, 05:00 AM)Narf Wrote: [ -> ]Some things are simpler than they seem ...



Code:
// application/config/routes.php
switch ($_SERVER['HTTP_HOST'])
{
   case 'sub.domain.tld':
       // your sub.domain.tld routes here
       break;
   case 'default.domain.tld':
   default:
       // your default domain routes here
       break;
}

Wouldn't this only work if your subdomain is pointing to the same root directory as your main domain?

Yes, but how else do you expect to be able to have domain-based routing within CI?

I was asking because a subdomain by default points to it's own directory in the root of your hosting
(09-23-2015, 05:24 AM)Martin7483 Wrote: [ -> ]I was asking because a subdomain by default points to it's own directory in the root of your hosting

This depends on your host, and in most cases it can be changed. You could also put a copy of the index.php file in each subdomain and modify each index.php file to point to the same directories for everything else, or you could setup separate application directories for each subdomain but share the system directory.
(09-23-2015, 05:00 AM)Narf Wrote: [ -> ]Some things are simpler than they seem ...


Code:
// application/config/routes.php
switch ($_SERVER['HTTP_HOST'])
{
   case 'sub.domain.tld':
       // your sub.domain.tld routes here
       break;
   case 'default.domain.tld':
   default:
       // your default domain routes here
       break;
}

this is a good one, but some controlller dosn't work