0

I have a Craft 2 site I've inherited that is using locales for multiple sites (each with their own domains). When I set things up initially, I got all the locales working without issue. I've been asked to add a new locale and I think I have everything setup properly, but when I test on local, the URL shows the main/default site rather than the new locale.

  • All content has been added
  • This setup uses nystudio107's multi-environment config
  • The new locale is setup in locales in Craft (in the code below it's denoted with "new" where applicable)
  • All other locales work fine (i.e. they come up in the browser as they should)
  • I'm using MAMP Pro
    • all the locales point to the same web root folder (and again, this works fine for other locales except the new one)
  • I added a new file for the new locale to craft/app/framework/i18n/data/ without issue

Here's the code (some sensitive info, like site names, removed) for craft/config/general.php:

<?php


// Ensure our urls have the right scheme
// URI_SCHEME defined by public/index.php

// The site url
define('SITE_URL', URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');

return array(
  '*' => array(
    'allowAutoUpdates' => false,
    'extraAllowedFileExtensions' => 'json',
    'omitScriptNameInUrls' => true,
    'siteUrl' => SITE_URL,
    'devMode' => false,
    // hide the control panel except from the main locale
    'cpTrigger' => (CRAFT_LOCALE == 'acme') ? 'admin' : 'no-access',

    /* standard site configs */
    'env' => CRAFT_ENVIRONMENT,

    'carouselAutoplay' => true, // autorotate the carousel?

    // NEW LOCALE? Add it here. (keep them alphabetic)
    'siteUrl' => array(
      'acme' => getenv('CRAFTENV_URL_acme'),
      'acme_austin' => getenv('CRAFTENV_URL_AUSTIN'),
      'acme_centor' => getenv('CRAFTENV_URL_CENTOR'),
      'acme_chicago' => getenv('CRAFTENV_URL_CHICAGO'),
      'acme_new => getenv('CRAFTENV_URL_NEW'),
      'acme_la' => getenv('CRAFTENV_URL_LA'),
      'acme_tampa' => getenv('CRAFTENV_URL_TAMPA'),
    ),
  ),

  'LOCAL' => array(
    'carouselAutoplay' => false, // autorotate the carousel?
    'devMode' => true,
    'allowAutoUpdates' => true,
    'defaultCookieDomain' => '.acme.local',
    'corsDomain' => URI_SCHEME.'acme.local',
    'environmentVariables' => array(
      'assetPath' => MAIN_ACME_PATH.'uploads/',
      'assetURL' => URI_SCHEME.'acme.local/'
    ),
  ),

  'STAGING' => array(
    // stripped out
    ),
  ),

  'PRODUCTION' => array(
    'defaultCookieDomain' => '.acme.org',
    'corsDomain' => URI_SCHEME.'acme.org',
    'environmentVariables' => array(
      'assetPath' => MAIN_FRIENDS_PATH.'uploads/',
      'assetURL' => URI_SCHEME.'acme.org/'
    ),
  ),
);

Here's the code in .env:

<?php
/**
 * Craft-Multi-Environment (CMS)
 * @author    nystudio107
 * @copyright Copyright (c) 2017 nystudio107
 * @link      https://nystudio107.com/
 * @package   craft-multi-environment
 * @since     1.0.4
 * @license   MIT
 *
 * This file should be renamed to '.env.php' and it should reside in your root
 * project directory (right next to example.env.php)
 * update the CHANGE_ME stuff...
 */

// Determine the incoming protocol
// arcustech issues: we are setting URI_SCHEME here instead of figuring it out
// one of: 'http://', 'https://'
$protocol = "http://"; // CHANGE_ME

// Determine the server hostname
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';

// determine the locale based on the server hostname.
// update the cases for your environment
// NEW LOCALE? ADD IT HERE, in $craftEnvVars and
// in config/general.php
$locale = 'acme'; // default
switch ($httpHost) {
  case 'acme.local':
    $locale = 'acme';
    break;
  case 'acmeaustin.local':
    $locale = 'acme_austin';
    break;
  case 'acmecentraloregon.local':
    $locale = 'acme_centor';
    break;
  case 'acmechicago.local':
    $locale = 'acme_chicago';
    break;
  case 'acmenew.local':
    $local = 'acme_new';
    break;
  case 'acmela.local':
    $locale = 'acme_la';
    break;
  case 'acmetampabay.local':
    $locale = 'acme_tampa';
    break;
}

// The $craftEnvVars are all auto-prefixed with CRAFTENV_ -- you can add
// whatever you want here and access them via getenv() using the prefixed name
$craftEnvVars = array(
  // The Craft environment we're running in.
  // one of: 'LOCAL', 'STAGING', 'PRODUCTION'
  'CRAFT_ENVIRONMENT' => 'LOCAL', // CHANGE_ME

  // all the urls for siteUrl // CHANGE_ME, ADD_TO_ME
  'URL_ACME' => $protocol.'acme.local',
  'URL_AUSTIN' => $protocol.'acmeaustin.local',
  'URL_CENTOR' => $protocol.'acmecentraloregon.local',
  'URL_CHICAGO' => $protocol.'acmechicago.local',
  'URL_NEW' => $protocol.'acmenew.local',
  'URL_LA' => $protocol.'acmela.local',
  'URL_TAMPA' => $protocol.'acmetampabay.local',

  'URI_SCHEME' => $protocol,

  // Database passwords here, not in git
  'DB_HOST' => 'localhost',

  // The name of the database to select.
  'DB_NAME' => 'acme_craft_local',  // CHANGE_ME

  // The database username to connect with.
  'DB_USER' => 'acme_db_username',  // CHANGE_ME

  // The database password to connect with.
  'DB_PASS' => 'acme_db_password',  // CHANGE_ME

  // stuff that doesn't change...
  'CRAFT_LOCALE' => $locale,
);

// Set all of the .env values, auto-prefixed with `CRAFTENV_`
foreach ($craftEnvVars as $key => $value) {
    putenv("CRAFTENV_{$key}={$value}");
}

Not sure where else to look or what else to try.

  • Is there an Apache virtualhost for the new domain? Not sure how MAMP generates them or if you need to manually add it. Ditto for your hosts file. – Judd Lyon Oct 23 '19 at 19:05

Your Answer

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

Browse other questions tagged or ask your own question.