Skip to content

Commit ab0d406

Browse files
authored
Merge pull request #2330 from cirrax/fix_rewrite
fix rewrite rules being ignored
2 parents 4086506 + 2aa7689 commit ab0d406

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

spec/defines/vhost_spec.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@
379379
'request_headers' => ['append MirrorID "mirror 12"'],
380380
'rewrites' => [
381381
{
382-
'rewrite_rule' => ['^index\.html$ welcome.html'],
382+
'rewrite_rule' => ['^index.html$ rewrites.html'],
383383
},
384384
],
385385
'filters' => [
@@ -392,7 +392,7 @@
392392
'FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no',
393393
],
394394
'rewrite_base' => '/',
395-
'rewrite_rule' => '^index\.html$ welcome.html',
395+
'rewrite_rule' => '^index.html$ welcome.html',
396396
'rewrite_cond' => ['%{HTTP_USER_AGENT} ^MSIE'],
397397
'rewrite_inherit' => true,
398398
'setenv' => ['FOO=/bin/true'],
@@ -733,9 +733,11 @@
733733
}
734734
it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') }
735735
it {
736-
is_expected.to contain_concat__fragment('rspec.example.com-rewrite').with(
737-
content: %r{^\s+RewriteOptions Inherit$},
738-
)
736+
is_expected.to contain_concat__fragment('rspec.example.com-rewrite')
737+
.with_content(%r{^\s+RewriteEngine On$})
738+
.with_content(%r{^\s+RewriteOptions Inherit$})
739+
.with_content(%r{^\s+RewriteBase /})
740+
.with_content(%r{^\s+RewriteRule \^index\.html\$ rewrites.html$})
739741
}
740742
it { is_expected.to contain_concat__fragment('rspec.example.com-scriptalias') }
741743
it { is_expected.to contain_concat__fragment('rspec.example.com-serveralias') }
@@ -1812,9 +1814,25 @@
18121814
end
18131815

18141816
it {
1815-
is_expected.to contain_concat__fragment('rspec.example.com-rewrite').with(
1816-
content: %r{^\s+RewriteOptions Inherit$},
1817+
is_expected.not_to contain_concat__fragment('rspec.example.com-rewrite')
1818+
.with_content(%r{^\s+RewriteOptions Inherit$})
1819+
.with_content(%r{^\s+RewriteEngine On$})
1820+
.with_content(%r{^\s+RewriteRule \^index\.html\$ welcome.html$})
1821+
}
1822+
end
1823+
context 'empty rewrites_without_rewrite_inherit' do
1824+
let(:params) do
1825+
super().merge(
1826+
'rewrite_inherit' => false,
1827+
'rewrites' => [],
18171828
)
1829+
end
1830+
1831+
it {
1832+
is_expected.not_to contain_concat__fragment('rspec.example.com-rewrite')
1833+
.with_content(%r{^\s+RewriteEngine On$})
1834+
.with_content(%r{^\s+RewriteRule \^index\.html\$ welcome.html$})
1835+
.without(content: %r{^\s+RewriteOptions Inherit$})
18181836
}
18191837
end
18201838

templates/vhost/_rewrite.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- if @rewrites -%>
1+
<%- if @rewrite_inherit or !@rewrites.empty? -%>
22
## Rewrite rules
33
RewriteEngine On
44
<%- if @rewrite_inherit -%>
@@ -38,7 +38,7 @@
3838
<%- end -%>
3939
<%- end -%>
4040
<%# reverse compatibility -%>
41-
<% if @rewrite_rule and !@rewrites -%>
41+
<% if @rewrite_rule and @rewrites.empty? -%>
4242
## Rewrite rules
4343
RewriteEngine On
4444
<%- if @rewrite_base -%>

0 commit comments

Comments
 (0)