Jump to content

Multi-section site using subdomains and single PW setup


Robert Zelník
 Share

Recommended Posts

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

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

  • 3 weeks later...
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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...