Skip to content

Commit

Permalink
Merge pull request #990 from soerenbe/feature/master/rewritemap_support
Browse files Browse the repository at this point in the history
Add RewriteMap support
  • Loading branch information
igalic committed Feb 17, 2015
2 parents dfcbecd + a530b41 commit 7be44e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ Modifies collected [request headers](http://httpd.apache.org/docs/current/mod/mo

#####`rewrites`

Creates URL rewrite rules. Expects an array of hashes, and the hash keys can be any of 'comment', 'rewrite_base', 'rewrite_cond', or 'rewrite_rule'. Defaults to 'undef'.
Creates URL rewrite rules. Expects an array of hashes, and the hash keys can be any of 'comment', 'rewrite_base', 'rewrite_cond', 'rewrite_rule' or 'rewrite_map'. Defaults to 'undef'.

For example, you can specify that anyone trying to access index.html is served welcome.html

Expand Down Expand Up @@ -1430,6 +1430,11 @@ Multiple rewrites and conditions are also possible
rewrite_base => /apps/,
rewrite_rule => ['^index\.cgi$ index.php', '^index\.html$ index.php', '^index\.asp$ index.html'],
},
{ comment => 'Rewrite to lower case',
rewrite_cond => ['%{REQUEST_URI} [A-Z]'],
rewrite_map => ['lc int:tolower'],
rewrite_rule => ['(.*) ${lc:$1} [R=301,L]'],
},
],
}
```
Expand Down
1 change: 1 addition & 0 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@
# - $rewrite_base
# - $rewrite_rule
# - $rewrite_cond
# - $rewrite_map
if $rewrites or $rewrite_rule {
concat::fragment { "${name}-rewrite":
target => "${priority_real}${filename}.conf",
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ class { 'apache': }
{ comment => 'test',
rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]',
rewrite_rule => ['^index\.html$ welcome.html'],
rewrite_map => ['lc int:tolower'],
}
],
}
Expand All @@ -1011,6 +1012,7 @@ class { 'apache': }
it { is_expected.to contain '#test' }
it { is_expected.to contain 'RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]' }
it { is_expected.to contain 'RewriteRule ^index.html$ welcome.html' }
it { is_expected.to contain 'RewriteMap lc int:tolower' }
end
end

Expand Down
7 changes: 7 additions & 0 deletions templates/vhost/_rewrite.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<%- end -%>
<%- end -%>
<%- end -%>
<%- if rewrite_details['rewrite_map'] -%>
<%- Array(rewrite_details['rewrite_map']).each do |commands| -%>
<%- Array(commands).each do |command| -%>
RewriteMap <%= command %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- Array(rewrite_details['rewrite_rule']).each do |commands| -%>
<%- Array(commands).each do |command| -%>
RewriteRule <%= command %>
Expand Down
15 changes: 15 additions & 0 deletions tests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@
}
]
}

# Rewrite a URL to lower case
apache::vhost { 'sixteenth.example.com non-ssl':
servername => 'sixteenth.example.com',
port => '80',
docroot => '/var/www/sixteenth',
rewrites => [
{ comment => 'Rewrite to lower case',
rewrite_cond => ['%{REQUEST_URI} [A-Z]'],
rewrite_map => ['lc int:tolower'],
rewrite_rule => ['(.*) ${lc:$1} [R=301,L]'],
}
]
}

apache::vhost { 'sixteenth.example.com ssl':
servername => 'sixteenth.example.com',
port => '443',
Expand Down

0 comments on commit 7be44e4

Please sign in to comment.