diff --git a/README.md b/README.md index 089e0b005..d4a4d89aa 100644 --- a/README.md +++ b/README.md @@ -1594,6 +1594,31 @@ Sets the value for the [PassengerEnabled](http://www.modrails.com/documentation/ `php_admin_value` sets the value of the directory, and `php_admin_flag` uses a boolean to configure the directory. Further information can be found [here](http://php.net/manual/en/configuration.changes.php). +######`rewrites` + +Creates URL [`rewrites`](#rewrites) rules in vhost directories. Expects an array of hashes, and the hash keys can be any of 'comment', 'rewrite_base', 'rewrite_cond', or 'rewrite_rule'. + +```puppet + apache::vhost { 'secure.example.net': + docroot => '/path/to/directory', + directories => [ + { path => '/path/to/directory', + rewrites => [ { comment => 'Permalink Rewrites', + rewrite_base => '/' + }, + { rewrite_rule => [ '^index\.php$ - [L]' ] + }, + { rewrite_cond => [ '%{REQUEST_FILENAME} !-f', + '%{REQUEST_FILENAME} !-d', + ], + rewrite_rule => [ '. /index.php [L]' ], + } + ], + }, + ], + } +``` + ######`ssl_options` String or list of [SSLOptions](https://httpd.apache.org/docs/current/mod/mod_ssl.html#ssloptions), which configure SSL engine run-time options. This handler takes precedence over SSLOptions set in the parent block of the vhost. diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 12effe763..f8e26f7e2 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -982,6 +982,45 @@ class { 'apache': } end end + describe 'directory rewrite rules' do + it 'applies cleanly' do + pp = <<-EOS + class { 'apache': } + host { 'test.server': ip => '127.0.0.1' } + apache::vhost { 'test.server': + docroot => '/tmp', + directories => [ + { + path => '/tmp', + rewrites => [ + { + comment => 'Permalink Rewrites', + rewrite_base => '/', + }, + { rewrite_rule => [ '^index\.php$ - [L]' ] }, + { rewrite_cond => [ + '%{REQUEST_FILENAME} !-f', + '%{REQUEST_FILENAME} !-d', ], rewrite_rule => [ '. /index.php [L]' ], } + ], + }, + ], + } + EOS + apply_manifest(pp, :catch_failures => true) + end + + describe file("#{$vhost_dir}/25-test.server.conf") do + it { should be_file } + it { should contain '#Permalink Rewrites' } + it { should contain 'RewriteEngine On' } + it { should contain 'RewriteBase /' } + it { should contain 'RewriteRule ^index\.php$ - [L]' } + it { should contain 'RewriteCond %{REQUEST_FILENAME} !-f' } + it { should contain 'RewriteCond %{REQUEST_FILENAME} !-d' } + it { should contain 'RewriteRule . /index.php [L]' } + end + end + describe 'setenv/setenvif' do it 'applies cleanly' do pp = <<-EOS diff --git a/spec/defines/vhost_spec.rb b/spec/defines/vhost_spec.rb index ea7047935..e47765bf7 100644 --- a/spec/defines/vhost_spec.rb +++ b/spec/defines/vhost_spec.rb @@ -806,6 +806,40 @@ /^ <\/Directory>$/, ], }, + { + :title => 'should accept directory directives with rewrites array', + :attr => 'directories', + :value => [ + { + 'path' => '/opt/app3', + 'rewrites' => [ + { + 'comment' => 'Permalink Rewrites', + 'rewrite_base' => '/', + 'rewrite_rule' => [ '^index\.php$ - [L]' ], + }, + { + 'rewrite_cond' => [ + '%{REQUEST_FILENAME} !-f', + '%{REQUEST_FILENAME} !-d', + ], + 'rewrite_rule' => [ '. /index.php [L]' ], + } + ] + } + ], + :match => [ + /^ $/, + /^ #Permalink Rewrites$/, + /^ RewriteEngine On$/, + /^ RewriteBase \/$/, + /^ RewriteRule \^index\\.php\$ - \[L\]$/, + /^ RewriteCond %{REQUEST_FILENAME} !-f$/, + /^ RewriteCond %{REQUEST_FILENAME} !-d$/, + /^ RewriteRule . \/index.php \[L\]$/, + /^ <\/Directory>$/, + ], + }, { :title => 'should accept location for provider', :attr => 'directories', @@ -946,6 +980,40 @@ /^ <\/Directory>$/, ], }, + { + :title => 'should accept directory directives with rewrites array', + :attr => 'directories', + :value => [ + { + 'path' => '/opt/app3', + 'rewrites' => [ + { + 'comment' => 'Permalink Rewrites', + 'rewrite_base' => '/', + 'rewrite_rule' => [ '^index\.php$ - [L]' ], + }, + { + 'rewrite_cond' => [ + '%{REQUEST_FILENAME} !-f', + '%{REQUEST_FILENAME} !-d', + ], + 'rewrite_rule' => [ '. /index.php [L]' ], + } + ] + } + ], + :match => [ + /^ $/, + /^ #Permalink Rewrites$/, + /^ RewriteEngine On$/, + /^ RewriteBase \/$/, + /^ RewriteRule \^index\\.php\$ - \[L\]$/, + /^ RewriteCond %{REQUEST_FILENAME} !-f$/, + /^ RewriteCond %{REQUEST_FILENAME} !-d$/, + /^ RewriteRule . \/index.php \[L\]$/, + /^ <\/Directory>$/, + ], + }, { :title => 'should accept location for provider', :attr => 'directories', diff --git a/templates/vhost/_directories.erb b/templates/vhost/_directories.erb index ea2db8bdc..accd72448 100644 --- a/templates/vhost/_directories.erb +++ b/templates/vhost/_directories.erb @@ -165,6 +165,30 @@ <%- if directory['fcgiwrapper'] -%> FcgidWrapper <%= directory['fcgiwrapper']['command'] %> <%= directory['fcgiwrapper']['suffix'] %> <%= directory['fcgiwrapper']['virtual'] %> <%- end -%> + <%- if directory['rewrites'] -%> + # Rewrite rules + RewriteEngine On + <%- directory['rewrites'].flatten.compact.each do |rewrite_details| -%> + <%- if rewrite_details['comment'] -%> + #<%= rewrite_details['comment'] %> + <%- end -%> + <%- if rewrite_details['rewrite_base'] -%> + RewriteBase <%= rewrite_details['rewrite_base'] %> + <%- end -%> + <%- if rewrite_details['rewrite_cond'] -%> + <%- Array(rewrite_details['rewrite_cond']).each do |commands| -%> + <%- Array(commands).each do |command| -%> + RewriteCond <%= command %> + <%- end -%> + <%- end -%> + <%- end -%> + <%- Array(rewrite_details['rewrite_rule']).each do |commands| -%> + <%- Array(commands).each do |command| -%> + RewriteRule <%= command %> + <%- end -%> + <%- end -%> + <%- end -%> + <%- end -%> <%- if directory['custom_fragment'] -%> <%= directory['custom_fragment'] %> <%- end -%>