Redirect Subdomain to Folder

how do i set this up? I tried using htaccess and subdomain mulltienviroment config files with routes, but did not get it working.

htaccess example:
multi enviroment config files:
routing: see docs too. can not post more than two links yet (says forum).

Many thanks in andvance for your help.

www. has kirby installed and content for blog
–+ /content/blog

blog. should link to blog content but keep subdomain prefix
view => www. but
url => blog.

I wouldn’t do a rewrite but set the doc root of the subdomain to the subfolder of the domain if that’s possible.

i tried that, but results in permission denied (13) error on function session-start. can not write to tmp folder. but since it works for root i did bot know how to fix it.

like described here.

did some further research and it seems that kirby being installed in www. sets its php sessions (kirby/toolkit/lib/s.php) to that domain. which is default and totally ok.
when blog. tries to load session it fails since cross (sub)domain sessions are not allowed.

its probably the easiest solution to clone the current cms and mirror it having only the content of the blog.

has anyone a better idea or done a subdomain redirect to folder successfully? how did you do it?

Do you have full access to your web server and is it an apache? If yes, you should set up different virtual hosts and for you will need to use mod_proxy as mentioned in your htaccess example link from stackoverflow.

Another solution, merely a dirty trick, will make use of a frameset with a hidden frame. is then pointing to a frameset with two frames, one is an empty page; the other, which fills up the whole space, comes from But this might stem from ancient times and could be a no-go in modern web programming. Using mod_proxy would be more state of art, I guess.

yes, setting up a virtual host and using a redirection rule with mod_proxy flag [P] (for proxy) could be another way. will take a look at it. thx.

better solution from @lukasbestle, but did not try myself.

One quick question about the solution you posted – you said you didn’t try it out, but you clearly understand something I’m missing. How would the file structure look for this?
By far, I’ve created folders for subdomains and put their content, site and assets in there but my localhost is having none of it (and yes i did change the site.php) so I’m wondering if that was what I should have done.
Help? Please?

i just assumed that the quoted thread referring to would work.

depending on site.php content

$domains = array('', '');     
// changed to
$domains = array('', '');

the file structure from the example would look like that:

1 Like

i dont think you can test the multi site setup on localhost since the site.php gets the server name

$domain  = server::get('server_name');

which you could fake for testing purposes.


// /site.php

$kirby   = kirby();
$domain  = server::get('server_name');
$domains = array('', '');

function is_localhost() {
    $whitelist = array( '', '::1' );
    if( in_array( $_SERVER['REMOTE_ADDR'], $whitelist) )
        return true;
if(is_localhost()) $domain = '';

if(in_array($domain, $domains)) {

but i would recommend live testing.

1 Like