Commit a84b7ed7 authored by Adrian Rossouw's avatar Adrian Rossouw

Re-instate redirects regressed. Use modrewrite for redirects, and no longer a...

Re-instate redirects regressed. Use modrewrite for redirects, and no longer a separate vhost. #872064
parent da61c413
...@@ -19,15 +19,35 @@ ...@@ -19,15 +19,35 @@
SetEnv db_port <?php print urlencode($db_port); ?> SetEnv db_port <?php print urlencode($db_port); ?>
<?php if (!$this->redirection && is_array($this->aliases)) :
foreach ($this->aliases as $alias_url) :
if (trim($alias_url)) : ?>
ServerAlias <?php print $alias_url; ?>
<?php <?php
endif; if (sizeof($this->aliases)) {
endforeach; print "\n ServerAlias " . implode("\n ServerAlias ", $this->aliases) . "\n";
endif; ?>
if ($this->redirection || $ssl_redirection) {
print "\n RewriteEngine on";
if ($ssl_redirection) {
// The URL we want to direct to can't be this virtual host,
// so we redirect the ServerName too.
print "\n RewriteCond %{HTTP_HOST} {$this->uri} [OR]";
}
print "\n RewriteCond %{HTTP_HOST} " .
implode(" [OR]\n RewriteCond %{HTTP_HOST} ", $this->aliases) . " [NC]\n";
if ($ssl_redirection && !$this->redirection) {
// When we are redirecting for SSL, but not in place of aliases,
// redirect to the same HTTP host on SSL.
print " RewriteRule ^/*(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]\n";
}
else {
print " RewriteRule ^/*(.*)$ {$redirect_url}/$1 [L,R=301]\n";
}
}
}
?>
<?php print $extra_config; ?> <?php print $extra_config; ?>
...@@ -38,7 +58,3 @@ ...@@ -38,7 +58,3 @@
</VirtualHost> </VirtualHost>
<?php
if ($this->redirection) {
// require(dirname(__FILE__) . '/vhost_redirect.tpl.php');
}
<VirtualHost *:<?php print $http_port; ?>>
<?php if ($this->site_mail) : ?>
ServerAdmin <?php print $this->site_mail; ?>
<?php endif;?>
<?php if (is_array($this->aliases) && count($this->aliases)): ?>
ServerName <?php print array_pop($this->aliases); ?>
<?php if (count($this->aliases)): ?>
ServerAlias <?php print join(" ", $this->aliases); ?>
<?php endif; ?>
<?php else:
# this should never happen and has the potential of creating an infinite redirection loop
?>
ServerName <?php print $this->uri ?>
<?php endif; ?>
<?php if ($ssl_redirect): ?>
RedirectMatch permanent ^(.*) https://<?php print $this->uri ?>$1
<?php else: ?>
RedirectMatch permanent ^(.*) http://<?php print $this->uri ?>$1
<?php endif; ?>
</VirtualHost>
...@@ -30,15 +30,20 @@ ...@@ -30,15 +30,20 @@
SSLCertificateKeyFile <?php print $ssl_cert_key; ?> SSLCertificateKeyFile <?php print $ssl_cert_key; ?>
<?php if (!$this->redirection && is_array($this->aliases)) : <?php
foreach ($this->aliases as $alias_url) : if (sizeof($this->aliases)) {
if (trim($alias_url)) : ?> print "\n ServerAlias " . implode("\n ServerAlias ", $this->aliases) . "\n";
ServerAlias <?php print $alias_url; ?>
if ($this->redirection) {
print "\n RewriteEngine on";
print "\n RewriteCond %{HTTP_HOST} " .
implode(" [OR]\n RewriteCond %{HTTP_HOST} ", $this->aliases) . " [NC]\n";
print " RewriteRule ^/*(.*)$ https://{$this->uri}/$1 [L,R=301]\n";
}
}
?>
<?php
endif;
endforeach;
endif; ?>
<?php print $extra_config; ?> <?php print $extra_config; ?>
...@@ -51,34 +56,6 @@ ...@@ -51,34 +56,6 @@
<?php endif; ?> <?php endif; ?>
<?php <?php
if ($this->ssl_enabled != 2) : include('http/apache/vhost.tpl.php');
// Generate the standard virtual host too.
include('http/apache/vhost.tpl.php');
else :
// Generate a virtual host that redirects all HTTP traffic to https.
?> ?>
<VirtualHost *:<?php print $http_port; ?>>
<?php if ($this->site_mail) : ?>
ServerAdmin <?php print $this->site_mail; ?>
<?php endif;?>
ServerName <?php print $this->uri ?>
<?php if (is_array($this->aliases)) :
foreach ($this->aliases as $alias_url) :
if (trim($alias_url)) : ?>
ServerAlias <?php print $alias_url; ?>
<?php
endif;
endforeach;
endif; ?>
RedirectMatch permanent ^(.*) <?php print $ssl_redirect_url ?>$1
</VirtualHost>
<?php endif; ?>
...@@ -134,6 +134,8 @@ class provisionConfig_http_site extends provisionConfig_http { ...@@ -134,6 +134,8 @@ class provisionConfig_http_site extends provisionConfig_http {
$this->aliases = explode(",", $this->aliases); $this->aliases = explode(",", $this->aliases);
} }
$this->aliases = array_filter($this->aliases, 'trim');
if (!$this->site_enabled) { if (!$this->site_enabled) {
$this->template = $this->disabled_template; $this->template = $this->disabled_template;
} }
......
...@@ -48,7 +48,7 @@ class provisionService_http_public extends provisionService_http { ...@@ -48,7 +48,7 @@ class provisionService_http_public extends provisionService_http {
$data['http_port'] = $this->server->http_port; $data['http_port'] = $this->server->http_port;
// We assign this generic catch all for standard http. // We assign this generic catch all for standard http.
// The SSL based services will override this with the // The SSL based services will override this with the
// correct ip address. // correct ip address.
...@@ -64,6 +64,10 @@ class provisionService_http_public extends provisionService_http { ...@@ -64,6 +64,10 @@ class provisionService_http_public extends provisionService_http {
// TODO: move away from drush_get_context entirely. // TODO: move away from drush_get_context entirely.
if ($config == 'site') { if ($config == 'site') {
// DO not create it with the port here. Protocol only is enough.
$data['redirect_url'] = "http://{$this->context->uri}";
$data = array_merge($data, drush_get_context('site')); $data = array_merge($data, drush_get_context('site'));
} }
......
...@@ -38,13 +38,14 @@ class provisionService_http_ssl extends provisionService_http_public { ...@@ -38,13 +38,14 @@ class provisionService_http_ssl extends provisionService_http_public {
function config_data($config = null, $class = null) { function config_data($config = null, $class = null) {
$data = parent::config_data($config, $class); $data = parent::config_data($config, $class);
$data['http_ssl_port'] = $this->server->http_ssl_port; $data['http_ssl_port'] = $this->server->http_ssl_port;
$data['ssl_redirect_url'] = "https://{$this->context->uri}";
if ($data['http_ssl_port'] != $this->default_ssl_port()) {
$data['ssl_redirect_url'] .= ":{$data['http_ssl_port']}";
}
if ($config == 'site' && $this->context->ssl_enabled) { if ($config == 'site' && $this->context->ssl_enabled) {
if ($this->context->ssl_enabled == 2) {
$data['ssl_redirection'] = TRUE;
$data['redirect_url'] = "https://{$this->context->uri}";
}
if ($ssl_key = $this->context->ssl_key) { if ($ssl_key = $this->context->ssl_key) {
// Retrieve the paths to the cert and key files. // Retrieve the paths to the cert and key files.
// they are generated if not found. // they are generated if not found.
......
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