Multi-Site

Pro Feature

Statamic's "multi-site" capabilities are designed to manage a single site with multiple localizations, variations, or sections running on one or more domains or subdomain. It can be used to manage translations, country-specific versions of a company site, and other similar use cases.

Overview

Statamic can be configured to handle multiple "sites". A site is a way of localized version of your content - whether another language, region, or even company or brand (think Proctor & Gamble).

Each site can have different base URLs:

  • subdomains: example.com and fr.example.com
  • subdirectories: example.com and example.com/fr/
  • different domains: hello.com and bonjour.com

Converting from Single to Multiple Sites

The default single-site setup uses a folder structure optimized for hand editing, but when using a multi-site setup the folder structure is a bit more complex. If you already have a site with content, switching to a multi-site setup will require moving files and folders around.

Luckily for you, this conversion can be done automatically with the following command:

php please multisite

More details on how to convert to a multi-site setup

Configuration

Let's look at a basic site configuration, and then we'll walk through each configuration option.

# config/statamic/sites.php
 
return [
'sites' => [
'default' => [
'name' => config('app.name'),
'locale' => 'en_US',
'url' => '/',
]
]
];

Sites

Every Statamic install needs at least one site, whether you are using multiple sites or not. Building zero sites is a bad way to build a website and clients will probably challenge any invoices.

Locale

Each site has a locale which is used to format region-specific data (like date strings).

URL

A URL is also required, which defines where statamic will serve and generate all URLs relative to.

Site URLs

As mentioned above, each site needs to define a url.

The default site url is /, which is portable and works fine in most typical sites. Statamic uses a little magic to work out what a full URL should be, based on the domain the site is running on.

Best Practice

It can be a good idea to change this to a fully qualified, absolute URL. This ensures that server/environment configurations or external quirks interfere with that "magic". Using an environment variable is an ideal solution here.

'sites' => [
'en' => [
// ...
'url' => env('APP_URL')
],
'fr' => [
// ...
'url' => env('APP_URL').'fr/'
]
]
# production
APP_URL=https://mysite.com/
 
# development
APP_URL=http://mysite.test/

Text Direction

If your site or sites have different text directions, for example if you have an English and a Hebrew version, you can define the direction in the config and use it on your front-end.

'sites' => [
'en' => [
'name' => 'English',
],
'he' => [
'name' => 'Hebrew',
'direction' => 'rtl',
]
]
<html dir="{{ site:direction }}">
Hot Tip!

Statamic's direction is ltr by default. You only need to set direction when your site is rtl.

Additional Attributes

You may also add an array of arbitrary attributes to your site's config, which can later be accessed with the site variable .

'sites' => [
'en' => [
'name' => 'English',
'attributes' => [
'theme' => 'standard',
]
],
]
<body class="theme-{{ site:attributes:theme }}">
Hot Tip!

Nothing fancy happens here, the values are passed along "as is" to your templates. If you need them to be editable, or store more complex data, you could use Globals.

Views

Views can be organized into site directories.

If a requested view exists in a subdirectory with the same name as your site, it will load it instead. This allows you have site-specific views without any extra configuration.

# config/statamic/sites.php
 
'sites' => [
'site_one' => [ /* ... */ ],
'site_two' => [ /* ... */ ],
]
resources/views/
site_one/
home.antlers.html
home.antlers.html
page.antlers.html

For example, given template: home, Statamic will load site_one/home because that view exists in the subdirectory. If you were to have template: page, it would load the one in the root directory because there's no site-specific variant.

Hot Tip!

This feature can be combined with the AMP feature. You can nest an amp view subdirectory inside a site subdirectory.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →