Robert Zelník Posted January 12, 2012 Share Posted January 12, 2012 I would like to create a site with multiple sections. Each section will have it's own subdomain. The section/subdomain will represent the first level of menu tree on a single ProcessWire installation. The webhosting is configured to map all subdomain requests to the same directory. Is there any way to configure ProcessWire or mod_rewrite to map the subdomain name as the first level of the menu tree? Link to comment Share on other sites More sharing options...
apeisa Posted January 12, 2012 Share Posted January 12, 2012 More about this: http://processwire.com/talk/topic/680-multiple-sites-from-one-install/page__hl__domain__fromsearch__1 Link to comment Share on other sites More sharing options...
ryan Posted January 12, 2012 Share Posted January 12, 2012 Just thinking about this a little more, another possible approach you could take would be to make your root level of pages consistent with the hostname that it should be accessed at. So your root level of pages might be named like this: /domain.com/ /sub.domain.com/ /other-domain.com/ Then your homepage template file could be the gateway, using URL segments. You'd need to turn on URL segments in the homepage template settings first. Then you'd do this, or something like it (haven't tested, just writing in browser): <?php if(count($input->urlSegments) && $config->httpHost != 'www.default-domain.com') { // convert urlSegments to a URL like: /sub.domain.com/path/to/page/ $url = '/' . $config->httpHost . '/' . implode('/', $input->urlSegments); // get the page. throw 404 if not found. $p = $pages->get($url); if(!$p->id) throw new Wire404Exception(); // render the page and get it's output $out = $p->render(); // URLs will have the httpHost in them, so replace these in the output // so user doesn't see hostname in the URLs $out = str_replace("/{$config->httpHost}/", "/", $out); echo $out; } else { // continue about rendering homepage for default domain } Link to comment Share on other sites More sharing options...
Robert Zelník Posted January 28, 2012 Author Share Posted January 28, 2012 Ryan, your solution looks good. I put your code in my template, file head.inc. I set 'urlSegments' => 1 in wire/core/Template.php. The $input->urlSegments always returns empty array for me. Perhaps I am doing something wrong? Link to comment Share on other sites More sharing options...
ryan Posted January 29, 2012 Share Posted January 29, 2012 I set 'urlSegments' => 1 in wire/core/Template.php Are you saying that you set it directly in code? What I actually meant was that you'd wan to edit the homepage template, click on the 'URLs' tab and check the box that says to enable URL segments. Though if you needed to do it in code (like for a module installation or something) then you could do this: $homepage = $pages->get('/'); $template = $homepage->template; $template->urlSegments = 1; $template->save(); But unless you are building a module install() function or something like that, I recommend just going and editing the template settings directly. Also note that we now have core support for multi-site support using separate /site/ directories: http://processwire.com/api/modules/multi-site-support/ Link to comment Share on other sites More sharing options...
apeisa Posted January 29, 2012 Share Posted January 29, 2012 Ryan, isn't multiple site support on core little bit different? In core it supports multiple sites with their own databases, but shared core files (wire folder). But what I think that Robert is after is multiple domains from same install (shared database, users etc). Same thing that I mentioned here: http://processwire.c...om-one-install/ (haven't yet tested that, but that requirement will come soon so I will). We probably need some better terms to differentiate these two things. EDIT: So to be clear: your code on this topic will provide different "multisite" than the core method? Link to comment Share on other sites More sharing options...
ryan Posted January 29, 2012 Share Posted January 29, 2012 That's correct that the method currently in the core does require it's own site directory and database, though shares the same PW installation and web account/web root. It's an entirely different method than what we're talking about here. But I've just been trying to mention it as a side note in any related discussion (not always sure who's looking for what). The code outlined in this topic is more of an untested theory. Though I don't see any reason why it shouldn't work. I would eventually like to have a core method for running sites on the same DB too. Link to comment Share on other sites More sharing options...
Robert Zelník Posted January 31, 2012 Author Share Posted January 31, 2012 Are you saying that you set it directly in code? Yes, I set it directly in the core because I didn't know that I can change it on the web interface. Now I know. I agree, it's better to not change the core. We probably need some better terms to differentiate these two things. Apeisa, we can differentiate that by naming "multi-site-single-db" vs "multi-site-multi-db". I will try your suggestions and let you know what's happened. Thanks for help. Link to comment Share on other sites More sharing options...
Robert Zelník Posted February 2, 2012 Author Share Posted February 2, 2012 I was unsuccessful with URL segments gateway, so I decided to follow the "multiple-site, multiple-database" path. It works well for me. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now