Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Multisite routing for ProcessWire
// source:
class Multisite extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => 'Multisite',
'version' => 1,
'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 /
$_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: tai";
$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']);
return $fields;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment