2

How can I cover both "www.domain.com" and "domain.com" with the same settings in my config file? My current file is set up like this:

return array(
    '*' => array(
       // Settings here
    ),

    // Local
    'domain.dev' => array(
       // Settings here
    ),

    // Staging
    'staging.domain.com' => array(
        // Settings here
    ),

    // Production
    'www.domain.com' => array(
       // Settings here
    )
);

Can I just remove the www from the last entry under “Production” to have those settings apply to both the naked domain and the www subdomain?

And if I'm including the www in my siteUrl config setting in Production, will that create any conflicts if visitors end up at a naked url without the www subdomain specified?

Thanks!

4

What I like to do is explicitly set CRAFT_ENVIRONMENT in my index.php:

switch($_SERVER['SERVER_NAME']) {
  case 'domain.dev':
    define('CRAFT_ENVIRONMENT', 'LOCAL');
    break;
  case 'staging.domain.com':
    define('CRAFT_ENVIRONMENT', 'STAGING');
    break;
  case 'www.domain.com':
  case 'domain.com':
    define('CRAFT_ENVIRONMENT', 'PRODUCTION');
    break;
}

Then in the config file:

return array(
  '*' => array(
    // Settings here
  ),
  'LOCAL' => array(
    // Settings here
  ),
  'STAGING' => array(
    // Settings here
  ),
  'PRODUCTION' => array(
    // Settings here
  )
);

When you set CRAFT_ENVIRONMENT you may want to use the switch default for LOCAL or for PRODUCTION - there are good arguments for going either way.

A separate question is whether you should have people accessing your site at both www.domain.com and domain.com. The answer is most probably no. Pick one, and use .htaccess (on apache) or whatever other method, to redirect either all the www to non-www or the other way around. Otherwise you will have duplicate content, which confuses the search engines (and generally looks unprofessional).

| improve this answer | |
  • Thanks for the tip Marion. If I wanted to use the switch default for PRODUCTION would I write it like this: default: define('CRAFT_ENVIRONMENT', 'PRODUCTION'); break; } ? – Adam Snetman Dec 3 '14 at 20:25
  • Sorry for the nonexistent multi-line formatting. Hope you can make sense of that. – Adam Snetman Dec 3 '14 at 20:27
  • yes, exactly... – Marion Newlevant Dec 3 '14 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.