Skip to content

Commit 5b92f91

Browse files
committed
Merge pull request #483 from antaflos/support_aliasmatch
Add support for AliasMatch directives
2 parents 7351991 + b5b75d6 commit 5b92f91

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,16 @@ Setting `add_listen` to 'false' stops the vhost from creating a listen statement
472472

473473
#####`aliases`
474474

475-
Passes a list of hashes to the vhost to create `Alias` statements as per the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). Each hash is expected to be of the form:
475+
Passes a list of hashes to the vhost to create `Alias` or `AliasMatch` statements as per the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). Each hash is expected to be of the form:
476476

477-
```puppet
478-
aliases => [ { alias => '/alias', path => '/path/to/directory' } ],
477+
```
478+
aliases => [
479+
{ aliasmatch => '^/image/(.*)\.jpg$', path => '/files/jpg.images/$1.jpg' }
480+
{ alias => '/image', path => '/ftp/pub/image' },
481+
],
479482
```
480483

481-
For `Alias` to work, each will need a corresponding `<Directory /path/to/directory>` or `<Location /path/to/directory>` block.
484+
For `Alias` and `AliasMatch` to work, each will need a corresponding `<Directory /path/to/directory>` or `<Location /path/to/directory>` block. The `Alias` and `AliasMatch` directives are created in the order specified in the `aliases` paramter. As described in the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html) more specific `Alias` or `AliasMatch` directives should come before the more general ones to avoid shadowing.
482485

483486
**Note:** If `apache::mod::passenger` is loaded and `PassengerHighPerformance true` is set, then `Alias` may have issues honouring the `PassengerEnabled off` statement. See [this article](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) for details.
484487

spec/defines/vhost_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,32 @@
358358
/^ Alias \/css \/opt\/someapp\/css$/,
359359
],
360360
},
361+
{
362+
:title => 'should accept an aliasmatch hash',
363+
:attr => 'aliases',
364+
## XXX As mentioned above, rspec-puppet drops the $1. Thus, these
365+
# tests don't work.
366+
#:value => { 'aliasmatch' => '^/image/(.*).gif', 'path' => '/files/gifs/$1.gif' },
367+
#:match => [/^ AliasMatch \^\/image\/\(\.\*\)\.gif \/files\/gifs\/\$1\.gif$/],
368+
},
369+
{
370+
:title => 'should accept a array of alias and aliasmatch hashes mixed',
371+
:attr => 'aliases',
372+
## XXX As mentioned above, rspec-puppet drops the $1. Thus, these
373+
# tests don't work.
374+
#:value => [
375+
# { 'alias' => '/css', 'path' => '/files/css' },
376+
# { 'aliasmatch' => '^/image/(.*).gif', 'path' => '/files/gifs/$1.gif' },
377+
# { 'aliasmatch' => '^/image/(.*).jpg', 'path' => '/files/jpgs/$1.jpg' },
378+
# { 'alias' => '/image', 'path' => '/files/images' },
379+
#],
380+
#:match => [
381+
# /^ Alias \/css \/files\/css$/,
382+
# /^ AliasMatch \^\/image\/\(.\*\)\.gif \/files\/gifs\/\$1\.gif$/,
383+
# /^ AliasMatch \^\/image\/\(.\*\)\.jpg \/files\/jpgs\/\$1\.jpg$/,
384+
# /^ Alias \/image \/files\/images$/
385+
#],
386+
},
361387
{
362388
:title => 'should accept a suPHP_Engine',
363389
:attr => 'suphp_engine',

templates/vhost/_aliases.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<% if @aliases and ! @aliases.empty? -%>
22
## Alias declarations for resources outside the DocumentRoot
33
<%- [@aliases].flatten.compact.each do |alias_statement| -%>
4-
<%- if alias_statement["alias"] != '' and alias_statement["path"] != ''-%>
4+
<%- if alias_statement["path"] != '' -%>
5+
<%- if alias_statement["alias"] and alias_statement["alias"] != '' -%>
56
Alias <%= alias_statement["alias"] %> <%= alias_statement["path"] %>
7+
<%- elsif alias_statement["aliasmatch"] and alias_statement["aliasmatch"] != '' -%>
8+
AliasMatch <%= alias_statement["aliasmatch"] %> <%= alias_statement["path"] %>
9+
<%- end -%>
610
<%- end -%>
711
<%- end -%>
812
<% end -%>

0 commit comments

Comments
 (0)