A Kirby plugin for routing and managing multiple domains within a single Kirby installation.
The plugin automatically handles routing for multiple domains and replaces URLs in the rendered HTML output:
- Routing: Intercepts all requests and maps them to the correct content folder based on the domain
- URL Replacement: In the rendered output, all URLs are intelligently trimmed:
- links within current domain (same folder): Converted to relative paths
- links to sibling domain (different folder): Converted to the full absolute URLs
To install the Multidomain Router plugin via composer, run:
composer require gerritvanaaken/multidomain-routerMake sure you are in the root directory of your Kirby project when running this command.
After installation, the plugin will be available at site/plugins/multidomain-router/. You can then continue with the configuration as described below.
Download and copy the full plugin folder into site/plugins/.
There are two methods to configure your domains:
Add the domain configuration directly in your site/config/config.php:
<?php
return [
'praegnanz.multidomain-router.sites' => [
[
'domain' => 'https://example-domain-one.com',
'folder' => 'example-domain-one',
'error' => 'example-domain-one/error' //optional
],
[
'domain' => 'https://example-domain-two.com',
'folder' => 'example-domain-two',
'error' => 'example-domain-two/error' //optional
]
]
];Configuration Options:
domain(required): Full URL including protocol, no trailing slashfolder(required): Content folder name, without any slasheserror(optional): Path to custom error page (e.g.'folder-name/error')
If you prefer to configure domains through the Panel:
- Add the Multidomain config to your
site/blueprints/site.yml, usingextend:
title: Site
tabs:
content:
label: Seiten
icon: page
sections:
pages:
type: pages
multidomains:
extends: multidomain-router- Refresh the Panel and configure your domains:
- Open the Panel and go to Site Settings
- Locate the "Multidomain" section
- Click "+ Add" to configure a new site
- Enter the folder name (e.g.
example-domain-one) - Enter the domain (e.g.
https://example-domain-one.com) - Optionally select an error page
- Don't forget to save! ✓
Note: If domains are configured in the config file (Method A), the Panel configuration will be ignored.
To create the required content folders for each domain, follow these steps:
-
Navigate to your site's
contentdirectory (usuallysite/contentin your Kirby installation). -
Create a new folder for each domain.
- The folder name must exactly match the
foldervalue you set in your multidomain configuration. - For example:
site/content/example-domain-one/ site/content/example-domain-two/
- The folder name must exactly match the
-
Add content to each folder as usual.
- Each folder will represent the homepage and pages for that particular domain.
- The typical structure inside a folder:
site/content/example-domain-one/home.txt site/content/example-domain-one/1_rooms/rooms.txt site/content/example-domain-two/1_rooms/1_penthouse/room.txt - Add your regular Kirby pages (folders ending in
.txt/subfolders) inside the domain folder as you would for a single-site setup.
Tips:
- If a domain has a custom error page, make sure to create the corresponding error page in the respective folder, e.g.:
site/content/example-domain-one/error/default.txt site/content/example-domain-two/error/default.txt - Folder names and structure should remain consistent with your configuration to ensure correct routing.
That's it! Each domain will serve content from its respective folder.
/hotel-kirby/room→/room/restaurant-kirby/lunch→https://restaurant-kirby.de/lunchhttps://hotel-kirby.de/hotel-kirby/room→/room
/restaurant-kirby/lunch→/lunch/hotel-kirby/room→https://hotel-kirby.de/roomhttps://restaurant-kirby.de/restaurant-kirby/lunch→/lunch
MIT
Gerrit van Aaken ([email protected])