--- mod_url.c.org	2007-05-28 00:38:01.000000000 +0900
+++ mod_url.c	2007-05-28 00:45:36.000000000 +0900
@@ -62,6 +62,8 @@
 
 #include <iconv.h>
 
+#define CHECK_REDURL_ENCODE_LICENSE
+
 /* mod_url.c:: fix mismatched URL encoding between server and clients
  *   by Won-Kyu Park <wkpark@kldp.org>
  * 
@@ -72,12 +74,14 @@
  *
  * 2000: initial release
  * 2000/10/11: fix for glibc-2.1.x glibc-2.2
- * 2002: fix for glibc-2.2 iconv: by JoungKyun Kim <http://www.oops.org>
+ * 2002: fix for glibc-2.2 iconv: by JoungKyun.Kim <http://oops.org>
  * 2004/08/03: add 'ServerEncoding' 'ClientEncoding' options
  *  - add per-dir support
  * 2004/11/25: fix #300597: set default values for ServerEncoding and ClientEncoding
  * 2004/11/25: fix #300597:
  *  - check 'ServerEncoding' and 'ClientEncoding' before iconv_open()
+ * 2007/05/28: added check_redurl_encode function for IE7
+ *  by JoungKyun.Kim <http://oops.org>
  *
  * Usage:
  *
@@ -98,6 +102,10 @@
 
 MODULE_VAR_EXPORT module redurl_module;
 
+#ifdef CHECK_REDURL_ENCODE_LICENSE
+static unsigned char hexchars[] = "0123456789ABCDEF";
+#endif
+
 typedef struct {
     int enabled;
     const char *server_encoding;
@@ -203,6 +211,36 @@ static const command_rec redurl_cmds[] =
     { NULL }
 };
 
+#ifdef CHECK_REDURL_ENCODE_LICENSE
+/*
+ * The check_redurl_encode function follows PHP license.
+ * See also http://www.php.net/license/3_01.txt.
+ *
+ * If you want this license, commented upper CHECK_REDURL_ENCODE_LICENSE
+ * constant.
+ */
+char * check_redurl_encode (const char *s, int len, int *retlen)
+{
+	register int x, y;
+	unsigned char *str;
+
+	str = (unsigned char *) malloc(sizeof (unsigned char) * (len * 3));
+	for (x = 0, y = 0; len--; x++, y++) {
+		str[y] = (unsigned char) s[x];
+		if ( str[y] < 33 || str[y] > 126 ) {
+			str[y++] = '%';
+			str[y++] = hexchars[(unsigned char) s[x] >> 4];
+			str[y] = hexchars[(unsigned char) s[x] & 15];
+		}
+	}
+	str[y] = '\0';
+	if (retlen)
+		*retlen = y;
+
+	return ((char *) str);
+}
+#endif
+
 static int check_redurl(request_rec *r)
 {
     urlconfig *cfg;
@@ -315,12 +353,25 @@ static int check_redurl(request_rec *r)
 	 * ret > 0: strlen of converted URL in the glibc 2.1.[2,3]
 	 * flen == tlen then URL is ascii */
 	    char *nuri;
+#ifdef CHECK_REDURL_ENCODE_LICENSE
+		char *enc = check_redurl_encode (buf, strlen (buf), NULL);
+#endif
 
-	    nuri = ap_pstrcat(r->pool, buf,
+		nuri = ap_pstrcat(r->pool,
+#ifdef CHECK_REDURL_ENCODE_LICENSE
+			      enc,
+#else
+	              buf,
+#endif
 			      r->parsed_uri.query ? "?" : "",
 			      r->parsed_uri.query ? r->parsed_uri.query : "",
 			      NULL);
 
+#ifdef CHECK_REDURL_ENCODE_LICENSE
+		if ( enc )
+			free (enc);
+#endif
+
 	    ap_table_setn(r->headers_out, "Location",
 			  ap_construct_url(r->pool, nuri, r));
 

