Skip to content

Quicktip: Serving a page on its own domain

Basic setup

If you want to serve a landing page or your blog on its own domain or a subdomain, you can render the subpage directly. To achieve this, you can modify the index.php like this:

/index.php
<?php

require __DIR__ . '/kirby/bootstrap.php';

if ($_SERVER['SERVER_NAME'] === 'blog.domain.com' && $_SERVER['REQUEST_URI'] === '/' ) 
    echo (new Kirby)->render('blog');
} else {
    echo (new Kirby)->render();
}

With the if statement, we check for the subdomain and serve the blog page if the REQUEST_URI is the root otherwise we start Kirby like normal.

Depending on context (e.g. if the page contains links to other pages of the site), it might make sense to set the default URL in your config.php to make sure that other links still point to the main domain.

/site/config/config.php
return [
    'url' => 'https://domain.com'
];

Extending the example

  • You can all a page model for the blog page to make sure to render the correct URL in your navigation
  • You might want to refine this basic example if you need to make subpages work for this page