Skip to content

Commit

Permalink
Resolves MODULES 1369 RedirectMatch rules do not work in Apache module
Browse files Browse the repository at this point in the history
The existing template creates a line of the format
RedirectMatch permanent /(test)
This can not work with apache as the URL is a mandatory part of the redirect. To resolve this the patch creates a new variable redirectmatch_dest which follows the same flow as the redirectmatch_status and redirectmatch_regexp variables.
All three variables must be supplied and will generate a line of the format
RedirectMatch permanent /(test) http://www.example.com
  • Loading branch information
Matoch committed Oct 2, 2014
1 parent 88f1ef4 commit c78f99c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1140,15 +1140,16 @@ Specifies the status to append to the redirect. Defaults to 'undef'.
}
```

#####`redirectmatch_regexp` & `redirectmatch_status`
#####`redirectmatch_regexp` & `redirectmatch_status` & `redirectmatch_dest`

Determines which server status should be raised for a given regular expression. Entered as an array. Defaults to 'undef'.
Determines which server status should be raised for a given regular expression and where to forward teh user to. Entered as an arrays. Defaults to 'undef'.

```puppet
apache::vhost { 'site.name.fdqn':
redirectmatch_status => ['404','404'],
redirectmatch_regexp => ['\.git(/.*|$)/','\.svn(/.*|$)'],
redirectmatch_dest => ['http://www.example.com/1','http://www.example.com/2'],
}
```

Expand Down
5 changes: 4 additions & 1 deletion manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
$redirect_status = undef,
$redirectmatch_status = undef,
$redirectmatch_regexp = undef,
$redirectmatch_dest = undef,
$rack_base_uris = undef,
$headers = undef,
$request_headers = undef,
Expand Down Expand Up @@ -601,9 +602,11 @@
# - $redirect_status_a
# - $redirectmatch_status
# - $redirectmatch_regexp
# - $redirectmatch_dest
# - $redirectmatch_status_a
# - $redirectmatch_regexp_a
if ($redirect_source and $redirect_dest) or ($redirectmatch_status and $redirectmatch_regexp) {
# - $redirectmatch_dest
if ($redirect_source and $redirect_dest) or ($redirectmatch_status and $redirectmatch_regexp and $redirectmatch_dest) {
concat::fragment { "${name}-redirect":
target => "${priority_real}-${filename}.conf",
order => 150,
Expand Down
1 change: 1 addition & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
'redirect_status' => 'temp',
'redirectmatch_status' => ['404'],
'redirectmatch_regexp' => ['\.git$'],
'redirectmatch_dest' => ['http://www.example.com'],
'rack_base_uris' => ['/rackapp1'],
'headers' => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
'request_headers' => ['append MirrorID "mirror 12"'],
Expand Down
6 changes: 4 additions & 2 deletions templates/vhost/_redirect.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
Redirect <%= "#{@redirect_status_a[i]} " %><%= source %> <%= @redirect_dest_a[i] %>
<%- end -%>
<% end -%>
<%- if @redirectmatch_status and @redirectmatch_regexp -%>
<%- if @redirectmatch_status and @redirectmatch_regexp and @redirectmatch_dest -%>
<% @redirectmatch_status_a = Array(@redirectmatch_status) -%>
<% @redirectmatch_regexp_a = Array(@redirectmatch_regexp) -%>
<% @redirectmatch_dest_a = Array(@redirectmatch_dest) -%>

## RedirectMatch rules
<%- @redirectmatch_status_a.each_with_index do |status, i| -%>
<% @redirectmatch_status_a[i] ||= @redirectmatch_status_a[0] -%>
<% @redirectmatch_regexp_a[i] ||= @redirectmatch_regexp_a[0] -%>
RedirectMatch <%= "#{@redirectmatch_status_a[i]} " %> <%= @redirectmatch_regexp_a[i] %>
<% @redirectmatch_dest_a[i] ||= @redirectmatch_dest_a[0] -%>
RedirectMatch <%= "#{@redirectmatch_status_a[i]} " %> <%= @redirectmatch_regexp_a[i] %> <%= @redirectmatch_dest_a[i] %>
<%- end -%>
<% end -%>

0 comments on commit c78f99c

Please sign in to comment.