7. Multisite

The PageBundle handles multisite out of the box. However due to some limitation of the Symfony API, the multisite support is done around 4 strategies:

Type

Description

host

you can configure a site per host. This strategy works out of the box with no changes.

host_by_locale

same than host, but try to retrieve the site by the Accept-Language header of the HTTP request.

host_with_path

you can configure site per host and per path. This strategy requires some changes.

host_with_path_by_locale

same than host with path, but try to retrieve the site by the Accept-Language header of the HTTP request.

7.1. Host Strategy

With this strategy it is possible to handle sites like :

Configure the sonata_page section as:

# config/packages/sonata_page.yaml

sonata_page:
    multisite: host

7.2. Host By Locale Strategy

This strategy handles the same sites than previous one.

Configure the sonata_page section as:

# config/packages/sonata_page.yaml

sonata_page:
    multisite: host_by_locale

7.3. Host and Path Strategy

With this strategy it is possible to handle sites like :

This strategy requires a dedicated runtime. So you need to modify your composer.json and declare SonataPagePathRuntime runtime.

"extra": {
    "runtime": {
        "class": "Sonata\\PageBundle\\Runtime\\SonataPagePathRuntime"
    }

Update your autoloader file with composer dump-autoload.

The last action is to configure the sonata_page section as:

# config/packages/sonata_page.yaml

sonata_page:
    multisite: host_with_path

7.4. Host and Path By Locale Strategy

This strategy requires a dedicated runtime. So you need to modify your composer.json and declare SonataPagePathRuntime runtime.

"extra": {
    "runtime": {
        "class": "Sonata\\PageBundle\\Runtime\\SonataPagePathRuntime"
    }

Update your autoloader file with composer dump-autoload.

The last action is to configure the sonata_page section as:

# config/packages/sonata_page.yaml

sonata_page:
    multisite: host_with_path_by_locale

Note

If you have a working site with the PageBundle, you just need to create a Site and update the page table and the snapshot table with the correct Site id value.