rse 99/01/01 11:50:24
Modified: src CHANGES
src/modules/standard mod_rewrite.c mod_rewrite.h
htdocs/manual/mod mod_rewrite.html
Log:
Two minor enhancements to mod_rewrite: First RewriteRule now also supports the
``nocase|NC'' flag (as RewriteCond already does for ages) to match case
insensitive (this especially avoids nasty patterns like `[tT][eE][sS][tT]').
Second two additional internal map functions `escape' and `unescape' were
added which can be used to escape/unescape to/from hex-encodings in URLs parts
(this is especially useful in combination with map lookups).
Submitted by: Magnus Bodin, Ian Kallen
Integrated and fixed by: Ralf S. Engelschall
Revision Changes Path
1.1187 +9 -0 apache-1.3/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.1186
retrieving revision 1.1187
diff -u -r1.1186 -r1.1187
--- CHANGES 1999/01/01 17:17:54 1.1186
+++ CHANGES 1999/01/01 19:50:20 1.1187
@@ -1,5 +1,14 @@
Changes with Apache 1.3.4
+ *) Two minor enhancements to mod_rewrite: First RewriteRule now also
+ supports the ``nocase|NC'' flag (as RewriteCond already does for ages)
to
+ match case insensitive (this especially avoids nasty patterns like
+ `[tT][eE][sS][tT]'). Second two additional internal map functions
+ `escape' and `unescape' were added which can be used to escape/unescape
+ to/from hex-encodings in URLs parts (this is especially useful in
+ combination with map lookups).
+ [Magnus Bodin, Ian Kallen, Ralf S. Engelschall]
+
*) Renamed the macro escape_uri() to ap_escape_uri() which was
forgotten (because it was a macro) in the symbol renaming process.
[Ralf S. Engelschall]
1.135 +46 -14 apache-1.3/src/modules/standard/mod_rewrite.c
Index: mod_rewrite.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- mod_rewrite.c 1999/01/01 19:05:12 1.134
+++ mod_rewrite.c 1999/01/01 19:50:22 1.135
@@ -501,6 +501,12 @@
else if (strcmp(a2+4, "toupper") == 0) {
new->func = rewrite_mapfunc_toupper;
}
+ else if (strcmp(a2+4, "escape") == 0) {
+ new->func = rewrite_mapfunc_escape;
+ }
+ else if (strcmp(a2+4, "unescape") == 0) {
+ new->func = rewrite_mapfunc_unescape;
+ }
else if (sconf->state == ENGINE_ENABLED) {
return ap_pstrcat(cmd->pool, "RewriteMap: internal map not
found:",
a2+4, NULL);
@@ -708,6 +714,7 @@
char *a3;
char *cp;
const char *err;
+ int mode;
sconf = (rewrite_server_conf *)
ap_get_module_config(cmd->server->module_config,
&rewrite_module);
@@ -726,16 +733,32 @@
"'\n", NULL);
}
+ /* arg3: optional flags field */
+ new->forced_mimetype = NULL;
+ new->forced_responsecode = HTTP_MOVED_TEMPORARILY;
+ new->flags = RULEFLAG_NONE;
+ new->env[0] = NULL;
+ new->skip = 0;
+ if (a3 != NULL) {
+ if ((err = cmd_rewriterule_parseflagfield(cmd->pool, new,
+ a3)) != NULL) {
+ return err;
+ }
+ }
+
/* arg1: the pattern
* try to compile the regexp to test if is ok
*/
- new->flags = RULEFLAG_NONE;
cp = a1;
if (cp[0] == '!') {
new->flags |= RULEFLAG_NOTMATCH;
cp++;
}
- if ((regexp = ap_pregcomp(cmd->pool, cp, REG_EXTENDED)) == NULL) {
+ mode = REG_EXTENDED;
+ if (new->flags & RULEFLAG_NOCASE) {
+ mode |= REG_ICASE;
+ }
+ if ((regexp = ap_pregcomp(cmd->pool, cp, mode)) == NULL) {
return ap_pstrcat(cmd->pool,
"RewriteRule: cannot compile regular expression '",
a1, "'\n", NULL);
@@ -749,18 +772,6 @@
*/
new->output = ap_pstrdup(cmd->pool, a2);
- /* arg3: optional flags field */
- new->forced_mimetype = NULL;
- new->forced_responsecode = HTTP_MOVED_TEMPORARILY;
- new->env[0] = NULL;
- new->skip = 0;
- if (a3 != NULL) {
- if ((err = cmd_rewriterule_parseflagfield(cmd->pool, new,
- a3)) != NULL) {
- return err;
- }
- }
-
/* now, if the server or per-dir config holds an
* array of RewriteCond entries, we take it for us
* and clear the array
@@ -917,6 +928,10 @@
|| strcasecmp(key, "QSA") == 0 ) {
cfg->flags |= RULEFLAG_QSAPPEND;
}
+ else if ( strcasecmp(key, "nocase") == 0
+ || strcasecmp(key, "NC") == 0 ) {
+ cfg->flags |= RULEFLAG_NOCASE;
+ }
else {
return ap_pstrcat(p, "RewriteRule: unknown flag '", key, "'\n",
NULL);
}
@@ -2964,6 +2979,23 @@
cp++) {
*cp = ap_tolower(*cp);
}
+ return value;
+}
+
+static char *rewrite_mapfunc_escape(request_rec *r, char *key)
+{
+ char *value;
+
+ value = ap_escape_uri(r->pool, key);
+ return value;
+}
+
+static char *rewrite_mapfunc_unescape(request_rec *r, char *key)
+{
+ char *value;
+
+ value = ap_pstrdup(r->pool, key);
+ ap_unescape_url(value);
return value;
}
1.59 +3 -0 apache-1.3/src/modules/standard/mod_rewrite.h
Index: mod_rewrite.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- mod_rewrite.h 1999/01/01 19:05:12 1.58
+++ mod_rewrite.h 1999/01/01 19:50:22 1.59
@@ -202,6 +202,7 @@
#define RULEFLAG_FORBIDDEN 1<<9
#define RULEFLAG_GONE 1<<10
#define RULEFLAG_QSAPPEND 1<<11
+#define RULEFLAG_NOCASE 1<<12
#define MAPTYPE_TXT 1<<0
#define MAPTYPE_DBM 1<<1
@@ -427,6 +428,8 @@
char *key);
static char *rewrite_mapfunc_toupper(request_rec *r, char *key);
static char *rewrite_mapfunc_tolower(request_rec *r, char *key);
+static char *rewrite_mapfunc_escape(request_rec *r, char *key);
+static char *rewrite_mapfunc_unescape(request_rec *r, char *key);
static char *select_random_value_part(request_rec *r, char *value);
static void rewrite_rand_init(void);
static int rewrite_rand(int l, int h);
1.41 +9 -0 apache-1.3/htdocs/manual/mod/mod_rewrite.html
Index: mod_rewrite.html
===================================================================
RCS file: /home/cvs/apache-1.3/htdocs/manual/mod/mod_rewrite.html,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- mod_rewrite.html 1998/11/09 16:44:08 1.40
+++ mod_rewrite.html 1999/01/01 19:50:23 1.41
@@ -751,6 +751,10 @@
Converts the looked up key to all upper case.
<LI><STRONG>tolower</STRONG>:<BR>
Converts the looked up key to all lower case.
+ <LI><STRONG>escape</STRONG>:<BR>
+ Translates special characters in the looked up key to hex-encodings.
+ <LI><STRONG>unescape</STRONG>:<BR>
+ Translates hex-encodings in the looked up key back to special
characters.
</UL>
<P>
<LI><STRONG>External Rewriting Program</STRONG><BR>
@@ -1584,6 +1588,11 @@
with CGI-scripts to force them to be processed by the CGI-script, the
chance is high that you will run into problems (or even overhead) on
sub-requests.
In these cases, use this flag.
+<P>
+<LI>'<STRONG><CODE>nocase|NC</CODE></STRONG>' (<STRONG>n</STRONG>o
<STRONG>c</STRONG>ase)<BR>
+ This makes the <EM>Pattern</EM> case-insensitive, <EM>i.e.</EM>, there
is
+ no difference between 'A-Z' and 'a-z' when <EM>Pattern</EM> is matched
+ against the current URL.
<P>
<LI>'<STRONG><CODE>qsappend|QSA</CODE></STRONG>' (<STRONG>q</STRONG>uery
<STRONG>s</STRONG>tring
<STRONG>a</STRONG>ppend)<BR>