I want to connect the directory (folder name) to the subdomain

Hello. It’s too difficult for me and I need help.
I recently created a website for a company. The company consists of four organizations. At first, there was no plan to divide the domains.
I thought of it as a submenu of the default address.

Default address.

  1. http://www.dy.co.kr/
  2. www.dy.co.kr/kr/dy-power
  3. www.dy.co.kr/kr/dy-auto
  4. www.dy.co.kr/kr/dy-innovate

But in this company, four organizations want to have different domains.
So I added a sub-domain of the default domain.

  1. power.dy.co.kr
  2. auto.dy.co.kr
  3. innovate.dy.co.kr

FTP

‘Power’ Directory(Other directories are still empty.)

I don’t know what to do next. I need help. :frowning:

I tried this, too. However, the default domain is accessed, and the subdomain (power.dy.co.kr) has an error.

<?php
require 'kirby/bootstrap.php';

$domain = 'dy.co.kr';

$mainUrl = 'http://'. $domain;

$sites = [
  'power.' => 'power',
  'auto.' => 'auto',
  'innovate.' => 'innovate',
];

$host = Url::host();
      
if ( ! isset($sites[$host])) {
    echo (new Kirby)->render();
} else {
    $root = $sites[$host];
    $url  = 'http://' . $host;
    
	$kirby = new Kirby([
        'roots' => [
            'index'   => __DIR__,
            'site'    => '/site',
            'content' => '/power/'. $root . '/content',
            'media'   => '/media',
            'assets'  => '/assets'
        ],
        'urls' => [
          'current'  => $mainUrl . '/panel',
          'api'  => $mainUrl . '/api',
          'panel'  => $mainUrl . '/panel',
          'media'  => $mainUrl . '/media',
          'assets' => $mainUrl . '/assets',
        ],
    ]);
    
    echo '<pre>';var_dump($kirby);echo '</pre>';die();
    
    echo $kirby->render();
}

Maybe revisit the docs again, there are some differences between your setup and how it should be: Using Kirby for multiple sites | Kirby CMS

For example this array, the key should be the domain name, the value the folder name etc.

Yes! That’s right. I used the name of the folder. The default website is in /www, and three folders to use as subdomains are also in it.

Again, the keys in that array have to be the domain names, not the folder name

And the domains all have to point to the same www folder. Please do it exactly like in the documentation.

Let’s say I create my multisite locally with MAMP Pro and I define two local domains (multisite.test and power.test) that point to the project root folder, in my case Users/me/public_html/multisite, my index.php would look like this:

<?php
require 'kirby/bootstrap.php';

$sites = [
  'multisite.test'   => __DIR__,
  'power.test'       => 'power',
];

$host = Url::host();
$root = $sites[$host];
$url  = 'http://' . $host;

$kirby = new Kirby([
  'roots' => [
    'index'   => __DIR__,
    'site'    => $root . '/site',
    'content' => $root . '/content',
    'media'   => $root . '/media',
    'assets'  => $root . '/assets'
  ],
  'urls' => [
    'media'  => $url . '/' . $root . '/media',
    'assets' => $url . '/' . $root . '/assets',
  ],
]);

echo $kirby->render();

Did I understand correctly? ‘index.php’ has been modified…!
In the folder used as a subdomain, there are ‘content’, ‘media’, ‘site’, and ‘assets’. (I got help from this article.)

I’ve read so many articles, and I’ve seen articles that modify ‘.htaccess’.
Is this necessary?
I’m so confused because it’s my first time. I’m sorry… :frowning:

<?php
require 'kirby/bootstrap.php';

$sites = [
  'dy.co.kr'   => __DIR__,
  'power.dy.co.kr'       => 'power',
  'auto.dy.co.kr'       => 'auto',
  'innovate.dy.co.kr'       => 'innovate',
];

$host = Url::host();
$root = $sites[$host];
$url  = 'http://' . $host;

$kirby = new Kirby([
  'roots' => [
    'index'   => __DIR__,
    'site'    => $root . '/site',
    'content' => $root . '/content',
    'media'   => $root . '/media',
    'assets'  => $root . '/assets'
  ],
  'urls' => [
    'media'  => $url . '/' . $root . '/media',
    'assets' => $url . '/' . $root . '/assets',
  ],
]);

echo $kirby->render();

Actually for me it is unclear what you are trying to achieve. If you want to serve 4 independent Kirby websites, the basic approach would be to have 4 independent directories, with Kirby installations. The multisite approach simplifies this by moving the Kirby program folder one level higher and the modified index.php dispatch the requests to the subfolder which belongs to the requested domain name. So, I wouldn’t install one website into the main folder and 3 websites in subfolders within, but 4 subfolders - like it is shown in the cookbook recipe for 2 websites.

Your webserver configuration however points to the main folder for all 4 sites.

It doesn’t really matter if all four sites are in separate folders or if the main stuff is in the web root, the procedure is the same. Although it probably makes the structure cleaner.

No.

But as I already said above (and @Adspectus repeated), all your domains have to point to the webroot.

What errors do you get?

@texnixe @Adspectus

Please check if what I understand is correct.

At first, this site had no subdomain concept. So the website that connects to the main domain did not have a separate folder, and it was directly worked on /www.

The directory was in /www.


These are three newly added subdomain directories.

The main domain is normally accessed.
Only one of the three subdomains is being tried, and there is an error.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at postmaster@power.dy.co.kr to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

If you restore your original setup (i.e. without the changes in index.php), do the subdomains work then? And show the same as the main domain? Once this works as expected, you can readd the changes in index.php

To check this error, it is imperative that the webserver logfile is inspected.

Do you have access to the logfiles? Do you have access to the webserver or virtual host configuration or do you have to live with a website which has to be placed into the www folder? So, what are your degrees of freedom here? :wink:

Okay, I just applied to the hosting company for web log viewing. I’ll contact you again when the application is completed! Thank you.