diff --git a/lib/apache/config.rb b/lib/apache/config.rb index 26943cc..7c88e80 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -127,10 +127,27 @@ module Apache self << "Include #{opts * " "}" end + def apache_alias(*opts) + self << "Alias #{quoteize(*opts) * " "}" + end + def rotatelogs(path, time) "|#{@rotate_logs_path} #{path} #{time}" end + def set_header(hash) + hash.each do |key, value| + output = "Header set #{quoteize(key)}" + case value + when String + output += " #{quoteize(value)}" + when Array + output += " #{quoteize(value.first)} #{value.last}" + end + self << output + end + end + private def writable?(path) if !File.directory? File.split(path).first diff --git a/lib/apache/rewrites.rb b/lib/apache/rewrites.rb index 8904f28..69f2953 100644 --- a/lib/apache/rewrites.rb +++ b/lib/apache/rewrites.rb @@ -13,6 +13,10 @@ module Apache def rewrites(&block) self + indent(RewriteManager.build(&block)) end + + def r301(*opt) + self << "Redirect permanent #{quoteize(*opt) * " "}" + end end class RewriteManager @@ -34,6 +38,13 @@ module Apache @rewrites << @rewrite end + def r301(*opts) + redirect = RedirectMatchPermanent.new + redirect.rule(*opts) + + @rewrites << redirect + end + def rewrite_test(from, to, opts = {}) orig_from = from.dup @rewrites.each do |r| @@ -48,7 +59,9 @@ module Apache end end - class RewriteRule + class MatchableThing + def tag; raise 'Override this method'; end + def initialize @from = nil @to = nil @@ -77,9 +90,17 @@ module Apache end - output << "RewriteRule #{[@from.source, @to, @options].flatten * " "}" + output << "#{tag} #{[@from.source, @to, @options].flatten * " "}" output * "\n" end +end + + class RewriteRule < MatchableThing + def tag; 'RewriteRule'; end + end + + class RedirectMatchPermanent < MatchableThing + def tag; 'RedirectMatch permanent'; end end end