Skip to content

Commit 238326c

Browse files
author
Marius Burkard
committed
Merge branch 'master' into 'master'
maindomain of aps-instance changeable and ordered rewrite rules in apache-vhost-conf 1. maindomain in apsinstance: Posibility to change main-domain of aps-instance over remote (in interface maind…omain is always the websites domain but over remote it's now possible to set an alias oder subdomain, that will be used in instance-settings. Important if e.g. wordpress-installation should run unter an aliasdomain instead of the websites domain) 2. append *-Rewrite-Rules to the end of rewrite-rules. With this it is possible to use - sub.domain.tld - *.domain.tld together with different subdir-redirects (with the usage of redirect-type L for sub.domain.tld). Before this change it was never possible to get it always working, because it depended on the order in database if it worked or not. See merge request !255
2 parents 982cb63 + a639ee6 commit 238326c

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ public function __construct($app)
4343
parent::__construct($app);
4444
}
4545

46-
46+
/**
47+
* Removes www from Domains name
48+
*
49+
* @param $filename the file to read
50+
* @return $sxe a SimpleXMLElement handle
51+
*/
52+
public function getMainDomain($domain) {
53+
if (substr($domain, 0, 4) == 'www.') $domain = substr($domain, 4);
54+
return $domain;
55+
}
56+
4757

4858
/**
4959
* Reads in a package metadata file and registers it's namespaces
@@ -344,9 +354,9 @@ public function createPackageInstance($settings, $packageid)
344354
$app->uses('tools_sites');
345355

346356
$webserver_id = 0;
347-
$websrv = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = ?", $settings['main_domain']);
357+
$websrv = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = ?", $this->getMainDomain($settings['main_domain']));
348358
if(!empty($websrv)) $webserver_id = $websrv['server_id'];
349-
$customerid = $this->getCustomerIDFromDomain($settings['main_domain']);
359+
$customerid = $this->getCustomerIDFromDomain($this->getMainDomain($settings['main_domain']));
350360

351361
if(empty($settings) || empty($webserver_id)) return false;
352362

@@ -565,13 +575,13 @@ public function validateInstallerInput($postinput, $pkg_details, $domains, $sett
565575
if(in_array($postinput['main_domain'], $domains))
566576
{
567577
$docroot = $app->db->queryOneRecord("SELECT document_root FROM web_domain
568-
WHERE domain = ?", $postinput['main_domain']);
578+
WHERE domain = ?", $this->getMainDomain($postinput['main_domain']));
569579
$new_path = $docroot['document_root'];
570580
if(substr($new_path, -1) != '/') $new_path .= '/';
571581
$new_path .= $main_location;
572582

573583
// Get the $customerid which belongs to the selected domain
574-
$customerid = $this->getCustomerIDFromDomain($postinput['main_domain']);
584+
$customerid = $this->getCustomerIDFromDomain($this->getMainDomain($postinput['main_domain']));
575585

576586
// First get all domains used for an install, then their loop them
577587
// and get the corresponding document roots as well as the defined

interface/lib/classes/remote.d/aps.inc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,15 @@ public function sites_aps_install_package($session_id, $primary_id, $params)
273273
return false;
274274
}
275275

276-
$sql = "SELECT * FROM web_domain WHERE domain = ?";
277-
$domain = $app->db->queryOneRecord($sql, $params['main_domain']);
276+
if (substr($params['main_domain'], 0, 4) == 'www.') {
277+
$domain = substr($params['main_domain'], 4);
278+
$sql = "SELECT * FROM web_domain WHERE domain = ? AND subdomain=?";
279+
$domain = $app->db->queryOneRecord($sql, $domain, 'www');
280+
}
281+
else {
282+
$sql = "SELECT * FROM web_domain WHERE domain = ?";
283+
$domain = $app->db->queryOneRecord($sql, $params['main_domain']);
284+
}
278285

279286
if (!$domain) {
280287
$this->server->fault('invalid parameters', 'No valid domain given.');

server/plugins-available/apache2_plugin.inc.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ function update($event_name, $data) {
12331233

12341234
// Rewrite rules
12351235
$rewrite_rules = array();
1236+
$rewrite_wildcard_rules = array();
12361237
if($data['new']['redirect_type'] != '' && $data['new']['redirect_path'] != '') {
12371238
if(substr($data['new']['redirect_path'], -1) != '/' && !preg_match('/^(https?|\[scheme\]):\/\//', $data['new']['redirect_path'])) $data['new']['redirect_path'] .= '/';
12381239
if(substr($data['new']['redirect_path'], 0, 8) == '[scheme]'){
@@ -1264,7 +1265,7 @@ function update($event_name, $data) {
12641265
'rewrite_add_path' => (substr($rewrite_target, -1) == '/' ? 'y' : 'n'));
12651266
break;
12661267
case '*':
1267-
$rewrite_rules[] = array( 'rewrite_domain' => '(^|\.)'.$this->_rewrite_quote($data['new']['domain']),
1268+
$rewrite_wildcard_rules[] = array( 'rewrite_domain' => '(^|\.)'.$this->_rewrite_quote($data['new']['domain']),
12681269
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
12691270
'rewrite_target' => $rewrite_target,
12701271
'rewrite_target_ssl' => $rewrite_target_ssl,
@@ -1363,7 +1364,7 @@ function update($event_name, $data) {
13631364
'rewrite_add_path' => (substr($rewrite_target, -1) == '/' ? 'y' : 'n'));
13641365
break;
13651366
case '*':
1366-
$rewrite_rules[] = array( 'rewrite_domain' => '(^|\.)'.$this->_rewrite_quote($alias['domain']),
1367+
$rewrite_wildcard_rules[] = array( 'rewrite_domain' => '(^|\.)'.$this->_rewrite_quote($alias['domain']),
13671368
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
13681369
'rewrite_target' => $rewrite_target,
13691370
'rewrite_target_ssl' => $rewrite_target_ssl,
@@ -1400,6 +1401,8 @@ function update($event_name, $data) {
14001401
} else {
14011402
$tpl->setVar('alias', '');
14021403
}
1404+
1405+
if (count($rewrite_wildcard_rules) > 0) $rewrite_rules = array_merge($rewrite_rules, $rewrite_wildcard_rules); // Append wildcard rules to the end of rules
14031406

14041407
if(count($rewrite_rules) > 0 || $vhost_data['seo_redirect_enabled'] > 0 || count($alias_seo_redirects) > 0) {
14051408
$tpl->setVar('rewrite_enabled', 1);

0 commit comments

Comments
 (0)