Commit e64fbbc9 authored by Falko Timme's avatar Falko Timme

- Added redirects for nginx.

- Added SEO redirects (both Apache & nginx) to redirect from non-www website to www website or vice versa.
- Introduced placeholder [scheme] for redirect paths for alias and subdomains; will be replaced with http or https, depending on what the visitor uses.
parent 9d6d30ac
ALTER TABLE `web_domain` ADD `seo_redirect` VARCHAR( 255 ) default NULL AFTER `redirect_path`;
ALTER TABLE `web_folder_user` ADD `server_id` INT( 11 ) NOT NULL DEFAULT '0' AFTER `sys_perm_other`;
\ No newline at end of file
......@@ -1493,6 +1493,7 @@ CREATE TABLE `web_domain` (
`ruby` enum('n','y') NOT NULL default 'n',
`redirect_type` varchar(255) default NULL,
`redirect_path` varchar(255) default NULL,
`seo_redirect` varchar(255) default NULL,
`ssl` enum('n','y') NOT NULL default 'n',
`ssl_state` varchar(255) NULL,
`ssl_locality` varchar(255) NULL,
......
......@@ -112,7 +112,7 @@ $form["tabs"]['domain'] = array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '@^(([.]{0})|(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(/[\w/_\.\-]{1,255}/))$@',
'regex' => '@^(([.]{0})|(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(\[scheme\]://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(/[\w/_\.\-]{1,255}/))$@',
'errmsg'=> 'redirect_error_regex'),
),
'default' => '',
......
......@@ -245,6 +245,12 @@ $form["tabs"]['redirect'] = array (
'width' => '30',
'maxlength' => '255'
),
'seo_redirect' => array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => '',
'value' => array('' => 'no_redirect_txt', 'non_www_to_www' => 'non_www_to_www_txt', 'www_to_non_www' => 'www_to_non_www_txt')
),
##################################
# ENDE Datatable fields
##################################
......
......@@ -112,7 +112,7 @@ $form["tabs"]['domain'] = array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '@^(([.]{0})|(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(/[\w/_\.\-]{1,255}/))$@',
'regex' => '@^(([.]{0})|(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(\[scheme\]://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(/[\w/_\.\-]{1,255}/))$@',
'errmsg'=> 'redirect_error_regex'),
),
'default' => '',
......
......@@ -73,4 +73,7 @@ $wb['save_certificate_txt'] = 'Save certificate';
$wb['create_certificate_txt'] = 'Create certificate';
$wb['delete_certificate_txt'] = 'Delete certificate';
$wb['nginx_directives_txt'] = 'nginx Direktiven';
$wb["seo_redirect_txt"] = 'SEO Redirect';
$wb["non_www_to_www_txt"] = 'Nicht-www -> www';
$wb["www_to_non_www_txt"] = 'www -> Nicht-www';
?>
......@@ -73,4 +73,7 @@ $wb['save_certificate_txt'] = 'Save certificate';
$wb['create_certificate_txt'] = 'Create certificate';
$wb['delete_certificate_txt'] = 'Delete certificate';
$wb["nginx_directives_txt"] = 'nginx Directives';
$wb["seo_redirect_txt"] = 'SEO Redirect';
$wb["non_www_to_www_txt"] = 'Non-www -> www';
$wb["www_to_non_www_txt"] = 'www -> non-www';
?>
\ No newline at end of file
......@@ -15,6 +15,12 @@
<label for="redirect_path">{tmpl_var name='redirect_path_txt'}</label>
<input name="redirect_path" id="redirect_path" value="{tmpl_var name='redirect_path'}" size="30" maxlength="255" type="text" class="textInput" />
</div>
<div class="ctrlHolder">
<label for="seo_redirect">{tmpl_var name='seo_redirect_txt'}</label>
<select name="seo_redirect" id="seo_redirect" class="selectInput formLengthHalf">
{tmpl_var name='seo_redirect'}
</select>
</div>
</fieldset>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
......
......@@ -11,6 +11,13 @@ server {
root <tmpl_var name='web_document_root_www'>;
<tmpl_if name='seo_redirect_enabled'>
if ($http_host = "<tmpl_var name='seo_redirect_origin_domain'>") {
rewrite ^ $scheme://<tmpl_var name='seo_redirect_target_domain'>$request_uri permanent;
}
</tmpl_if>
<tmpl_loop name="redirects">
if ($http_host ~* "<tmpl_var name='rewrite_domain'>$") {
......
......@@ -191,6 +191,14 @@
<tmpl_if name="rewrite_enabled">
RewriteEngine on
<tmpl_if name='seo_redirect_enabled'>
RewriteCond %{HTTP_HOST} ^<tmpl_var name='seo_redirect_origin_domain'>$ [NC]
RewriteRule ^(.*)$ http://<tmpl_var name='seo_redirect_target_domain'>/$1 [R=301,L]
</tmpl_if>
<tmpl_loop name="redirects">
RewriteCond %{HTTP_HOST} <tmpl_var name='rewrite_domain'>$ [NC]
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>
......@@ -405,9 +413,17 @@
<tmpl_if name="rewrite_enabled">
RewriteEngine on
<tmpl_if name='seo_redirect_enabled'>
RewriteCond %{HTTP_HOST} ^<tmpl_var name='seo_redirect_origin_domain'>$ [NC]
RewriteRule ^(.*)$ https://<tmpl_var name='seo_redirect_target_domain'>/$1 [R=301,L]
</tmpl_if>
<tmpl_loop name="redirects">
RewriteCond %{HTTP_HOST} ^<tmpl_var name='rewrite_domain'> [NC]
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target_ssl'>$1 <tmpl_var name='rewrite_type'>
</tmpl_loop>
</tmpl_if>
......
......@@ -671,34 +671,58 @@ class apache2_plugin {
if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
//$vhost_data['document_root'] = $data['new']['document_root'].'/web';
// Set SEO Redirect
if($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')){
$vhost_data['seo_redirect_enabled'] = 1;
if($data['new']['seo_redirect'] == 'non_www_to_www'){
$vhost_data['seo_redirect_origin_domain'] = $data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = 'www.'.$data['new']['domain'];
}
if($data['new']['seo_redirect'] == 'www_to_non_www'){
$vhost_data['seo_redirect_origin_domain'] = 'www.'.$data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = $data['new']['domain'];
}
} else {
$vhost_data['seo_redirect_enabled'] = 0;
}
$tpl->setVar($vhost_data);
// Rewrite rules
$rewrite_rules = array();
if($data['new']['redirect_type'] != '') {
if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/';
$rewrite_target = $data['new']['redirect_path'];
$rewrite_target_ssl = $data['new']['redirect_path'];
/* Disabled path extension
if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
$data['new']['redirect_path'] = $data['new']['document_root'].'/web'.realpath($data['new']['redirect_path']).'/';
}
*/
$rewrite_rules[] = array( 'rewrite_domain' => $data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
'rewrite_target' => $data['new']['redirect_path']);
switch($data['new']['subdomain']) {
case 'www':
$rewrite_rules[] = array( 'rewrite_domain' => 'www.'.$data['new']['domain'],
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
$rewrite_rules[] = array( 'rewrite_domain' => '^www.'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
'rewrite_target' => $data['new']['redirect_path']);
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
break;
case '*':
// TODO
//$rewrite_rules[] = array( 'rewrite_domain' => '*'.$alias['domain'],
// 'rewrite_type' => $alias['redirect_type'],
// 'rewrite_target' => $alias['redirect_path']);
$rewrite_rules[] = array( 'rewrite_domain' => $data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
break;
default:
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':'['.$data['new']['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
}
}
......@@ -729,27 +753,42 @@ class apache2_plugin {
$app->log('Add server alias: '.$alias['domain'],LOGLEVEL_DEBUG);
// Rewriting
if($alias['redirect_type'] != '') {
if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/';
if(substr($alias['redirect_path'],-1) != '/') $alias['redirect_path'] .= '/';
if(substr($alias['redirect_path'],0,8) == '[scheme]'){
$rewrite_target = 'http'.substr($alias['redirect_path'],8);
$rewrite_target_ssl = 'https'.substr($alias['redirect_path'],8);
} else {
$rewrite_target = $alias['redirect_path'];
$rewrite_target_ssl = $alias['redirect_path'];
}
/* Disabled the path extension
if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
$data['new']['redirect_path'] = $data['new']['document_root'].'/web'.realpath($data['new']['redirect_path']).'/';
}
*/
$rewrite_rules[] = array( 'rewrite_domain' => $alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
'rewrite_target' => $alias['redirect_path']);
switch($alias['subdomain']) {
case 'www':
$rewrite_rules[] = array( 'rewrite_domain' => 'www.'.$alias['domain'],
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
$rewrite_rules[] = array( 'rewrite_domain' => '^www.'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
'rewrite_target' => $alias['redirect_path']);
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
break;
case '*':
// TODO
//$rewrite_rules[] = array( 'rewrite_domain' => '*'.$alias['domain'],
// 'rewrite_type' => $alias['redirect_type'],
// 'rewrite_target' => $alias['redirect_path']);
$rewrite_rules[] = array( 'rewrite_domain' => $alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
break;
default:
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':'['.$alias['redirect_type'].']',
'rewrite_target' => $rewrite_target,
'rewrite_target_ssl' => $rewrite_target_ssl);
}
}
}
......
......@@ -650,7 +650,6 @@ class nginx_plugin {
$domain = $data['new']['ssl_domain'];
$key_file = $ssl_dir.'/'.$domain.'.key';
$crt_file = $ssl_dir.'/'.$domain.'.crt';
//$bundle_file = $ssl_dir.'/'.$domain.'.bundle';
if($domain!='' && $data['new']['ssl'] == 'y' && @is_file($crt_file) && @is_file($key_file) && (@filesize($crt_file)>0) && (@filesize($key_file)>0)) {
$vhost_data['ssl_enabled'] = 1;
......@@ -660,9 +659,21 @@ class nginx_plugin {
$app->log('SSL Disabled. '.$domain,LOGLEVEL_DEBUG);
}
//if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
//$vhost_data['document_root'] = $data['new']['document_root'].'/web';
// Set SEO Redirect
if($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')){
$vhost_data['seo_redirect_enabled'] = 1;
if($data['new']['seo_redirect'] == 'non_www_to_www'){
$vhost_data['seo_redirect_origin_domain'] = $data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = 'www.'.$data['new']['domain'];
}
if($data['new']['seo_redirect'] == 'www_to_non_www'){
$vhost_data['seo_redirect_origin_domain'] = 'www.'.$data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = $data['new']['domain'];
}
} else {
$vhost_data['seo_redirect_enabled'] = 0;
}
$tpl->setVar($vhost_data);
// Rewrite rules
......@@ -723,7 +734,9 @@ class nginx_plugin {
$app->log('Add server alias: '.$alias['domain'],LOGLEVEL_DEBUG);
// Rewriting
if($alias['redirect_type'] != '') {
if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/';
if(substr($alias['redirect_path'],-1) != '/') $alias['redirect_path'] .= '/';
if(substr($alias['redirect_path'],0,8) == '[scheme]') $alias['redirect_path'] = '$scheme'.substr($alias['redirect_path'],8);
/* Disabled the path extension
if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
$data['new']['redirect_path'] = $data['new']['document_root'].'/web'.realpath($data['new']['redirect_path']).'/';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment