Routing with Multiple Subdomains

By Jonathan Bradley (pmansion)
Ever want to have multiple admin routes and use subdomains?
After wanting to integrate 3 different parts of an application I wrote into one app, I looked and found some great pieces of information in the bakery on having more then one admin route and using admin routes on sub domains. So after playing and wanting an easier way to define everything.

Resources Used on the Bakery
Using CAKE_ADMIN for multiple user types - By Egbert Teeselink
Hosting Admin URLs on a Subdomain - By Nate

This is what we added to our boostrap.php

Component Class:

Download code <?php 
$url 
explode('.',env('HTTP_HOST'));

switch (
$url[0]) {
    case 
"admin":             
        
Configure::write('Routing.admin''admin');
        
$_GET["url"] = "admin/" str_replace('admin/','',$_GET['url']);
    break;
    case 
"support":        
        
Configure::write('Routing.admin''support');
        
$_GET["url"] = "support/" str_replace('support/','',$_GET['url']);
    break;
    default:
}
?>


Feedback is appreciated and hope this helps other people.

 

Comments 769

CakePHP Team Comments Author Comments
 

Comment

1 Security

If your authorization solution just checks empty($this->params[Configure::read('admin')]) to know if you are in admin section or not, then you have potencial security hole in your app, because (example) support_index() will be not 'prefixed and protected' action when hostname admin.example.com will be called - try to call admin.example.com/somecontroller/support_index and support.example.com/somecontroller/admin_index
Posted Aug 31, 2008 by Who Cares