]> gitweb.fluxo.info Git - puppet-apache.git/commitdiff
Adding support for canonical hostnames
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 18 May 2012 16:55:53 +0000 (13:55 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 18 May 2012 16:55:53 +0000 (13:55 -0300)
manifests/init.pp
templates/site.erb

index 96bd9f8ac37bc634616a1b65bf4d9324a57a10ca..6b7b382fc37d4775df4e2267d5f58255d2410771 100644 (file)
@@ -190,7 +190,8 @@ class apache {
               $mpm = true, $mpm_user = '', $mpm_group = '', $password = '*',
               $comment = '', $sshkey = absent,
               $groups = '', $shell = '/bin/false', $manage_user = true,
-              $ssl = false, $listen = '*', $https_redirect = false) {
+              $ssl = false, $listen = '*', $https_redirect = false,
+              $canonical = false) {
 
     $vhost = $filename ? {
       ''      => "$title",
index 3545e621115557cc406b0f987025e6706907ef11..4daf2bee2a9b786bcdb1065433d4be2acdcd7bcb 100644 (file)
@@ -3,12 +3,14 @@
    ServerName <%= title %>.<%= hosting_domain %>
 <% if server_alias != false %>   ServerAlias <%= server_alias %><% end %>
    DocumentRoot <%= docroot %>
- <% if https_redirect != false %>
+<% if https_redirect != false or canonical != false %>
+    RewriteEngine On
+<% end -%>
+<% if https_redirect != false %>
     # Use HTTP Strict Transport Security to force client to use secure connections only
     Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains"
 
     # Redirect all HTTP to HTTPS
-    RewriteEngine On
     RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [redirect=301]<% end %>
 <% if redirect_match != false %>   RedirectMatch ^/$ <%= protocol %>://<%= title %>.<%= hosting_domain %>/<%= redirect_match %><% end %>
 <% if redirect != false %>   Redirect <%= redirect %><% end %>
      AssignUserId <%= user %> <%= gid %>
    </IfModule>
 <% end %>   
+<% if canonical != false %>
+   RewriteCond %{HTTP_HOST}   !=<%= canonical %> [NC]
+   RewriteCond %{HTTP_HOST}   !=""
+   RewriteRule ^/(.*)         https://<%= canonical %>/$1 [L,R=301]
+<% end %>
 </VirtualHost>
 # end vhost for <%= title %>
 <% if ssl == true %>