Welcome Guest, Not a member yet? Register   Sign In
Wildcard subdomain points to controllers
#3

[eluser]Tom Schlick[/eluser]
nice i got it to work without htaccess! Smile im not sure if there are going to be any implications down the road with the uri structure since the subdomain name wont be in there but we will see....

here is MY_Routes.php

notice the subdomain code above all of the normal code

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Router Class
*
* Extends CI Router
*
* @author     Original by EllisLab - extension by CleverIgniters
* @see        http://codeigniter.com
*/

class MY_Router extends CI_Router {
    
    /**
     * Constructor
     *
     * @access    public
     */
    function MY_Router()
    {
        parent::CI_Router();
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Validate Routing Request
     *
     * @access    public
     */
    function _validate_request($segments)
    {
        
        // CHECK TO SEE IF SUBDOMAIN AND GO ON FROM THERE
        $http = explode('.', $_SERVER['HTTP_HOST']);
        if(count($http) > 2)
        {
            if($http[0] != 'www')
            {
                if(is_dir(APPPATH.'controllers/'.$http[0]))
                {
                    // Set the directory and remove it from the segment array
                    $this->set_directory($http[0]);
                    //$segments = array_slice($segments, 1);
                    
                    if (count($segments) > 0)
                    {
                        // Does the requested controller exist in the sub-folder?
                        if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                        {
                            show_404($this->fetch_directory().$segments[0]);
                        }
                    }
                    else
                    {
                        $this->set_class($this->default_controller);
                        $this->set_method('index');
                    
                        // Does the default controller exist in the sub-folder?
                        if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                        {
                            $this->directory = '';
                            return array();
                        }
                    
                    }
        
                    return $segments;
                }
                else
                {
                    if (file_exists(APPPATH.'controllers/'.$http[0].EXT))
                    {
                        return $segments;
                    }
                }
            }
        }
        //END SUBDOMAIN LOGIC HERE
        
        // Does the requested controller exist in the root folder?
        if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            return $segments;
        }
        

        // Is the controller in a sub-folder?
        if (is_dir(APPPATH.'controllers/'.$segments[0]))
        {        
            // Set the directory and remove it from the segment array
            $this->set_directory($segments[0]);
            $segments = array_slice($segments, 1);
            
            if (count($segments) > 0)
            {
                // Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    show_404($this->fetch_directory().$segments[0]);
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');
            
                // Does the default controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                    $this->directory = '';
                    return array();
                }
            
            }

            return $segments;
        }
        
        // Can't find the requested controller...
        show_404($segments[0]);
    }
}
?>

EDIT** made sure to check that the subdomain wasnt 'www'


Messages In This Thread
Wildcard subdomain points to controllers - by El Forum - 01-12-2009, 12:32 AM
Wildcard subdomain points to controllers - by El Forum - 01-12-2009, 02:18 AM
Wildcard subdomain points to controllers - by El Forum - 01-12-2009, 02:44 AM
Wildcard subdomain points to controllers - by El Forum - 01-12-2009, 03:03 AM
Wildcard subdomain points to controllers - by El Forum - 01-15-2009, 04:26 PM
Wildcard subdomain points to controllers - by El Forum - 03-17-2011, 11:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB