extern val skip : int -> mod_rewrite_flag;
extern val env : rewrite_arg -> rewrite_arg -> mod_rewrite_flag;
+extern type mod_rewrite_cond_flag;
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond">the
+ Apache documentation</a> for information on what these flags mean.}}
+
+extern val cond_nocase : mod_rewrite_cond_flag;
+extern val ornext : mod_rewrite_cond_flag;
+
extern val rewriteRule : no_spaces -> no_spaces -> [mod_rewrite_flag] -> [Vhost];
{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule">Apache
documentation for <tt>RewriteRule</tt></a>.}}
+extern val rewriteCond: no_spaces -> no_spaces -> [mod_rewrite_cond_flag] -> [Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond">Apache
+ documentation for <tt>RewriteCond</tt></a>.}}
+
+extern type proxy_port;
+{{A port number above 1024}}
+
extern val localProxyRewrite : no_spaces -> no_spaces -> proxy_port -> [Vhost];
{{All requests matching the regular expression in the first argument are
redirected to another HTTPD running on localhost at the given port, generating
-extern type proxy_port;
-{{A port number above 1024}}
-
-extern val localProxyPass : no_spaces -> no_spaces -> proxy_port -> [Vhost];
-extern val localProxyPassReverse : no_spaces -> no_spaces -> proxy_port -> [Vhost];
-{{Interface to Apache <tt>ProxyPass</tt> and <tt>LocalProxyPass</tt> for
- proxying to localhost only. The arguments give:
- <li> The URL prefix to treat as proxied</li>
- <li> The corresponding URL prefix on the other local server</li>
- <li> The port number of the local server</li>}}
+extern type proxy_target;
+{{URL prefix designating where to send proxied requests.
+ It can be any localhost URL on a port of at least 1024.
+ In addition, other allowed targets can be configured.}}
+
+extern val proxyPass : no_spaces -> proxy_target -> [Vhost];
+extern val proxyPassReverse : no_spaces -> proxy_target -> [Vhost];
+{{Interface to Apache <tt>ProxyPass</tt> and <tt>LocalProxyPass</tt>}}
val _ = Env.type_one "proxy_port"
Env.int
- (fn n => n >= 1024)
+ (fn n => n > 1024)
+
+val _ = Env.type_one "proxy_target"
+ Env.string
+ (fn s =>
+ let
+ fun default () = List.exists (fn s' => s = s') Config.Apache.proxyTargets
+ in
+ case String.fields (fn ch => ch = #":") s of
+ ["http", "//localhost", rest] =>
+ (case String.fields (fn ch => ch = #"/") rest of
+ port :: _ =>
+ (case Int.fromString port of
+ NONE => default ()
+ | SOME n => n > 1024 orelse default ())
+ | _ => default ())
+ | _ => default ()
+ end)
val _ = Env.type_one "rewrite_arg"
Env.string
| _ => NONE
+val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC"
+ | (EVar "ornext", _) => SOME "OR"
+ | _ => NONE
+
val vhostsChanged = ref false
write to;
write " [P]\n"))
-val () = Env.action_three "localProxyPass"
- ("from", Env.string, "to", Env.string, "port", Env.int)
- (fn (from, to, port) =>
- let
- val to =
- case to of
- "" => "/"
- | _ => if String.sub (to, 0) = #"/" then
- to
- else
- "/" ^ to
- in
- write "\tProxyPass\t";
- write from;
- write "\thttp://localhost:";
- write (Int.toString port);
- write to;
- write "\n"
- end)
-
-val () = Env.action_three "localProxyPassReverse"
- ("from", Env.string, "to", Env.string, "port", Env.int)
- (fn (from, to, port) =>
- let
- val to =
- case to of
- "" => "/"
- | _ => if String.sub (to, 0) = #"/" then
- to
- else
- "/" ^ to
- in
- write "\tProxyPassReverse\t";
- write from;
- write "\thttp://localhost:";
- write (Int.toString port);
- write to;
- write "\n"
- end)
+val () = Env.action_two "proxyPass"
+ ("from", Env.string, "to", Env.string)
+ (fn (from, to) =>
+ (write "\tProxyPass\t";
+ write from;
+ write "\t";
+ write to;
+ write "\n"))
+
+val () = Env.action_two "proxyPassReverse"
+ ("from", Env.string, "to", Env.string)
+ (fn (from, to) =>
+ (write "\tProxyPassReverse\t";
+ write from;
+ write "\t";
+ write to;
+ write "\n"))
val () = Env.action_three "rewriteRule"
("from", Env.string, "to", Env.string, "flags", Env.list flag)
write "]");
write "\n"))
+val () = Env.action_three "rewriteCond"
+ ("test", Env.string, "pattern", Env.string, "flags", Env.list cond_flag)
+ (fn (from, to, flags) =>
+ (checkRewrite ();
+ write "\tRewriteCond\t";
+ write from;
+ write "\t";
+ write to;
+ case flags of
+ [] => ()
+ | flag::rest => (write " [";
+ write flag;
+ app (fn flag => (write ",";
+ write flag)) rest;
+ write "]");
+ write "\n"))
+
end
SSL = true
with
localProxyRewrite "^/(.*)$" "$1" 6666;
- rewriteRule "^/foo.html" "/bar.html" [redirectWith redir300, nosubreq]
+ rewriteCond "hi" "there" [ornext];
+ rewriteRule "^/foo.html" "/bar.html" [redirectWith redir300, nosubreq];
end;
vhost "proxy" with
- localProxyPass "/proxyLand" "/otherProxyLand" 1234;
- localProxyPassReverse "/proxyLand" "/otherProxyLand" 1234
- end
+ proxyPass "/proxyLand" "http://localhost:1234/otherProxyLand";
+ proxyPassReverse "/proxyLand" "http://localhost:1234/otherProxyLand";
+ end;
+ vhost "lists" with
+ proxyPass "/mailman" "http://hcoop.net/cgi-bin/mailman";
+ end
end