You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Robert Simonson <si...@us.ibm.com> on 2001/09/04 19:01:15 UTC
[PATCH] mod_rewrite & SCRIPT_URx envvars
If the rewrite engine is off in the server config and turned on in a
directory
container, the SCRIPT_URx envvars were not being set. This patch is an
attempt
to fix that bug.
Rob Simonson
simo@us.ibm.com
==========================================================
--- mod_rewrite.c Tue Sep 4 10:57:15 2001
+++ mod_rewrite.c Tue Sep 4 11:16:16 2001
@@ -362,6 +362,58 @@
/*
+ * Set SCRIPT_URx envvars.
+ */
+static void set_rewrite_envvars(request_rec *r)
+{
+ const char *var, *thisurl, *thisserver;
+ char *thisport;
+ char buf[512];
+ unsigned int port;
+
+ /*
+ * add the SCRIPT_URL variable to the env. this is a bit complicated
+ * due to the fact that apache uses subrequests and internal
redirects
+ */
+
+ if (r->main == NULL) {
+ var = apr_pstrcat(r->pool, "REDIRECT_", ENVVAR_SCRIPT_URL, NULL);
+ var = apr_table_get(r->subprocess_env, var);
+ if (var == NULL) {
+ apr_table_setn(r->subprocess_env, ENVVAR_SCRIPT_URL, r->uri);
+ }
+ else {
+ apr_table_setn(r->subprocess_env, ENVVAR_SCRIPT_URL, var);
+ }
+ }
+ else {
+ var = apr_table_get(r->main->subprocess_env, ENVVAR_SCRIPT_URL);
+ apr_table_setn(r->subprocess_env, ENVVAR_SCRIPT_URL, var);
+ }
+
+ /*
+ * create the SCRIPT_URI variable for the env
+ */
+
+ /* add the canonical URI of this URL */
+ thisserver = ap_get_server_name(r);
+ port = ap_get_server_port(r);
+ if (ap_is_default_port(port, r)) {
+ thisport = "";
+ }
+ else {
+ apr_snprintf(buf, sizeof(buf), ":%u", port);
+ thisport = buf;
+ }
+ thisurl = apr_table_get(r->subprocess_env, ENVVAR_SCRIPT_URL);
+
+ /* set the variable */
+ var = apr_pstrcat(r->pool, ap_http_method(r), "://", thisserver,
thisport,
+ thisurl, NULL);
+ apr_table_setn(r->subprocess_env, ENVVAR_SCRIPT_URI, var);
+}
+
+/*
**
** the configuration commands
**
@@ -1024,6 +1076,11 @@
if (conf->state == ENGINE_DISABLED) {
return DECLINED;
}
+ /*
+ * Engine is on. If not proxy, Set SCRIPT_URx envvars.
+ */
+ if(!r->proxyreq)
+ set_rewrite_envvars(r);
/*
* check for the ugly API case of a virtual host section where no
@@ -1351,6 +1408,11 @@
return DECLINED;
}
}
+ /*
+ * Engine is on. If not proxy, Set SCRIPT_URx envvars.
+ */
+ if(!r->proxyreq)
+ set_rewrite_envvars(r);
/*
* remember the current filename before rewriting for later check