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: http://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory
multi enviroment config files: http://getkirby.com/docs/advanced/options
routing: see docs too. can not post more than two links yet (says forum).

Many thanks in andvance for your help.


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

blog. example.com: should link to blog content but keep subdomain prefix
view => www. example.com/blog but
url => blog. example.com

I wouldn’t do a rewrite but set the doc root of the subdomain blog.example.com to the subfolder of the www.example.com 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. example.com sets its php sessions (kirby/toolkit/lib/s.php) to that domain. which is default and totally ok.
when blog. example.com tries to load session it fails since cross (sub)domain sessions are not allowed.

BAD SOLUTION
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 blog.example.com 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. blog.example.com is then pointing to a frameset with two frames, one is an empty page; the other, which fills up the whole space, comes from www.example.com/blog. 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.

Hi,
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 http://getkirby.com/docs/advanced/customized-folder-setup#multi-site-setup would work.

depending on site.php content

$domains = array('domain-1.com', 'domain-2.com');     
// changed to
$domains = array('one.example.com', 'two.example.com');

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.

<?php

// /site.php

$kirby   = kirby();
$domain  = server::get('server_name');
$domains = array('one.example.com', 'two.example.com');

function is_localhost() {
    $whitelist = array( '127.0.0.1', '::1' );
    if( in_array( $_SERVER['REMOTE_ADDR'], $whitelist) )
        return true;
}
if(is_localhost()) $domain = 'one.example.com';

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

but i would recommend live testing.

1 Like