Multiple sites from one install
#1
Posted 25 November 2011 - 06:54 AM
Meaning you have one pw-site, let's say www.domain.com. There you have "campaign site" called www.domain.com/campaign/. All good so far. But what if pages from www.domain.com/campaign/ should be found from www.campaign.com?
Is that currently possible or would it require new pw-installation?
#3
Posted 25 November 2011 - 07:35 AM
#4
Posted 25 November 2011 - 07:38 AM
and their domain documentation: http://expressioneng...omainsetup.html
EDIT: Not looking for anything that complicated, just a way to serve one section of a site from own domain.
#5
Posted 25 November 2011 - 12:56 PM
But what if pages from www.domain.com/campaign/ should be found from www.campaign.com?
I think in this case you'd point both domain.com and campaign.com to the same IP. If your needs were simple, your template file could just check what host it's being served from, i.e.
<?php
if(strpos($config->httpHost, 'campaign.com') != false) {
// display or load something for campaign.com
} else {
// display or load something for domain.com
}
If your needs were more complex, then you could create an autoload module to handle your flow control. That module's init() would modify $_GET['it'] that hold's the path to the page requested. That $_GET['it'] var is the means by which PW's .htaccess file sends the requested URL to ProcessWire. Since an autoload module is init()'d before the page is loaded, it has the opportunity to change it, i.e.
<?php
public function init() {
if(strpos(wire('config')->httpHost, 'campaign.com') !== false) {
// change path like /about/contact/ to /campaign.com/about/contact/
$_GET['it'] = '/campaign.com/' . ltrim($_GET['it'], '/');
}
}
Then your campaign.com site structure would just be created below a page named '/campaign.com/' in your site tree. I've not tested this out, but I can't see any reason why it wouldn't work. Also, I'm sure the same thing could be accomplished via the .htaccess file rather than an autoload module, but I'd have to do more research on that before I could post an example.
#6
Posted 25 November 2011 - 01:25 PM
#7
Posted 25 November 2011 - 02:15 PM
For the other domain I chose /de-ch/ and /en-ch/. But I would like to put them in subfolders like /domain1/de/ and /domain/en/ etc. but then the additional path would show in url, which I didn't see any easy way. But then I also didn't come ask here
@somartist | modules created | support me, flattr my work flattr.com
#8
Posted 29 January 2012 - 08:23 AM
I’m not sure, if this would be a possible solution for the problem discussed here?
#9
Posted 02 March 2012 - 01:13 AM
Oliver: not sure I understand that context thing well enough to say if it could work here. It sounds like it could
#10
Posted 02 March 2012 - 05:45 AM
#11
Posted 02 March 2012 - 05:45 AM
#12
Posted 02 March 2012 - 07:32 AM
Anyways, I have this version up and running nicely:
<?php
class Multisite extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => 'Multisite',
'version' => 001,
'summary' => 'Allows multiple sites with different domains run from single PW-site and database.',
'singular' => true,
'autoload' => true,
);
}
public function init() {
$subdomains = explode("\n", strtolower($this->subdomains));
foreach($subdomains as $subdomain) {
$httpHost = strtolower(wire('config')->httpHost);
if(strpos($httpHost, $subdomain) !== false) {
$this->subdomain = $subdomain;
// change path like /about/contact/ to /campaign.com/about/contact/
$_GET['it'] = "/{$subdomain}/" . ltrim($_GET['it'], '/');
// hook for path method to make path() and url() methods context aware
$this->addHookAfter('Page::path', $this, 'modifyPath');
}
}
}
public function modifyPath($event) {
$event->return = str_replace("{$this->subdomain}/", '', $event->return);;
}
static public function getModuleConfigInputfields(array $data) {
$fields = new InputfieldWrapper();
$modules = wire('modules');
$field = $modules->get("InputfieldTextarea");
$field->name = "subdomains";
$field->label = "Other sites running from same install";
$field->description = "Add each domain for their own line. Don't add http or https, just simple domain like: www.example.com tai campaign.example.com";
$field->notes = "IMPORTANT: create homepage for each of these domains right on the root. Name should be exactly same as the domain you use here.";
$field->attr('value', $data['subdomains']);
$fields->add($field);
return $fields;
}
}
Edited by apeisa, 03 March 2012 - 02:43 PM.
Updated the code using hook on Page::path method
#14
Posted 03 March 2012 - 10:26 AM
This is still valid question though: Is there easy way to manipulate value that all url methods return? Using subUrl is fine, but I cannot use my old snippets and functions...
#15
Posted 03 March 2012 - 01:05 PM
This is still valid question though: Is there easy way to manipulate value that all url methods return? Using subUrl is fine, but I cannot use my old snippets and functions...
I was a little worried about making path() or url() hookable since they can feasibly be called hundreds or thousands of times in a request. I found a way to make functions hookable without adding any real overhead, except it requires defining two functions rather than one. But it'll be perfect for high-traffic function calls like this. So I've made Page::path hookable in this manner, and it's ready to go in the latest commit. Note that you'll want to hook the method, not the property. In the Page class, calling $page->path or $page->url resolves automatically to $page->path() or $page->url(), so if you are adding a hook, you want to hook the method.
I'm thinking we really only need $page->path() hookable (?), since it is what is used by $page->url(). The only difference between $page->url() and $page->path() is that $page->url() calls $page->path() and then prepends $config->urls->root to it. So $page->path is relative to the PW installation root, and $page->url is relative to the server's web root. Though in most installations, the two are the same, as most don't run PW from a subdirectory. The only other difference is that $page->url() trims off the trailing slash if its template says it should (I don't ever use that feature myself).
#16
Posted 03 March 2012 - 01:35 PM
I will test this very soon!
#17
Posted 03 March 2012 - 01:43 PM
#19
Posted 10 May 2012 - 10:24 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













