Jump to content

Serving different templates folder depending on domain name


Recommended Posts

Hi, I'm trying to serve a different templates folder depending on the domain name.

For example sub.domain.com would load a use a templates-dev folder.

I have got this working with the following code which I found on these forums:

// Map domains to template folders
$config->templates = [
    $production_url => 'templates',      // Production templates
    $sub_url              => 'templates-dev',  // Sub templates
];

// Set template paths dynamically based on HTTP_HOST
if (isset($_SERVER['HTTP_HOST']) && isset($config->templates[$_SERVER['HTTP_HOST']])) {
    $folder = $config->templates[$_SERVER['HTTP_HOST']];
    $config->urls->templates = "/site/$folder/";
    $config->paths->templates = dirname(__DIR__) . $config->urls->templates;
}

I've also added the sub domain in the allowed hosts in the config, as follows:

$config->httpHosts = array('www.domain.com', 'sub.domain.com');

This seems to work fine, apart from one slight issue...

The home page is blank, but returns a 200 status code. All other pages work fine. I just can't work out why this is happening. There are no errors in the logs or anything. Nothing to indicate a problem. I'm stumped to why this is happening.

Is there a better way to do this?

Thanks in advance.

 

 

 

 

 

Edited by shadowmoses
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...