Craft CMS domain setup

fortrabbit environments come with a testing URL. At some point you will very likely add your own domains.

For general information on how to add domains to your fortrabbit App, please see our domains article. For Craft CMS be sure to have set your domain's root path to the /web folder.

When installing Craft locally, it will ask you which domain you want to use. This local domain differs form the one you want to use in production. That's why it is stored in the PRIMARY_SITE_URL ENV var. The installer creates this ENV var in the .env file. In your fortrabbit production environment you may need to set PRIMARY_SITE_URL using the ENV var settings of your App.

Craft CMS uses @web alias internally when it deals with HTTP requests. Unless you define it, Craft will try to figure it out based on HTTP headers - which is not always possible. It's good practice to define it explicitly using PRIMARY_SITE_URL ENV var.

return [
  // Recommended aliases in config/general.php
  'aliases' => [
    '@web' => \craft\helpers\App::env('PRIMARY_SITE_URL') ?: '/',
    '@webroot' => dirname(__DIR__) . '/web'
  ],
];
php

You can also add multiple domains. From the fortrabbit side, just point them to the App's root path, configure routing and display of contents within Craft CMS and/or use additional htaccess rules.

# Multi site domain settings

For multi-site setups, you may need to hard-code the domains for each environment. Here is an example of that:

return [
  // fortrabbit (multi site)
  'production' => [
    'siteUrl' => [
      'en' => '//www.site.com',
      'nl' => '//www.site.nl',
    ],
  ],
  // local (multi site)
  'dev' => [
    'siteUrl' => [
      'en' => '//en.site.dev',
      'nl' => '//nl.site.dev',
    ],
  ],
];
php

Found a tpyo?Edit