We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7914
    • 137 Posts
    Hello,
    I am having difficulty making modx and apache play nice I think. I am setting up a sub domain context. I am using the "Sub domain via folder" method:
    http://rtfm.modx.com/display/revolution20/Creating+a+Subdomain+from+a+Folder+using+Virtual+Hosts


    my root index.php file:
    switch ($modx->getOption('http_host')) {
    	case 'm.mysite.com':
    	case 'm.mysite.com':
    		// if the http_host is of a specific domain, switch the context
    		$modx->switchContext('mobile');
    	break;	
    	default:
    		// fallback, go to main context
    		$modx->initialize('web');
    	break;
    }
    


    my "/mobile" index.php file:
    $modx->initialize('mobile');
    


    my "/mobile/config.core.php" file:
    define('MODX_CORE_PATH', '/Applications/MAMP/htdocs/mysite/trunk/core/');	
    define('MODX_CONFIG_KEY', 'config');
    


    I have set up the site_start and other required settings within the context as stated in the rtfm.

    My trouble:
    http://local.mysite.com/mobile works great.

    http://m.mysite.com fails to render. It just loads and loads and loads.

    If I update my root index.php file to this:
    switch ($modx->getOption('http_host')) {
    	case 'm.mysite.com':
    	case 'm.mysite.com':
    		// if the http_host is of a specific domain, switch the context
    		$modx->switchContext('mobile');
    	break;	
    	default:
    		// fallback, go to main context
    		$modx->initialize('mobile');
    	break;
    }
    


    So that everything points to the mobile context, it works. So there is something that I just haven’t connected yet but am failing to see just what it is.

    This is what my httpd.conf file looks like:
    <VirtualHost *:80>
        ServerName    local.mysite.com
        DocumentRoot  /Applications/MAMP/htdocs/mysite/trunk
    </VirtualHost>
    <VirtualHost *:80>
        ServerName    m.mysite.com
        DocumentRoot  /Applications/MAMP/htdocs/mysite/trunk/mobile
    </VirtualHost>
    


    I am using Revolution 2.0.8
      • 22303 MODX Staff
      • 10,725 Posts
      You don’t switchContext before calling initialize as you are doing in your index.php. That needs to be initialize(’mobile’), not switchContext(’mobile’). But since you are using Apache to direct requests to specific index.php’s via virtual host, you do not need any changes to your root index.php. It will initialize the web context, and the index.php in the subdomain with initialize(’mobile’). If this is failing it is because you have not setup the Apache VirtualHost configuration properly.