Attached is a patch for mod_speling.c in apache 1.3.6 and 1.3.9 that introduces a config-option to only check the spelling of an URL when there is no Referer-header, ie only when the user has entered the URL manually.
This makes it possible to have mod_speling enabled on a production-server without having users that have pages with misspelled URL's causing the server to fix the spelling very often (which can be very annoying if you have your users' home-directories mounted via nfs). It introduces the option CheckSpellingWithReferer (which defaults to on for no change in the default behaviour) which, when set to off, disables the check when there is no Referer-header. We have used this patch on our production-server running Apache 1.3.6 for a while now, it works for us :-) All credits for this patch should go to Magnus Jonsson <[EMAIL PROTECTED]>. With hopes of getting this included in the main Apache distribution. /Nikke - SysAdmin at the Academic Computer Club, Umeå University, Sweden -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Niklas Edmundsson, Admin @ {acc,hpc2n,ing}.umu.se | [EMAIL PROTECTED] --------------------------------------------------------------------------- Printers do it without wrinkling the sheets. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--- ../../../../dist/src/modules/standard/mod_speling.c Mon Jan 25 19:12:41 1999 +++ mod_speling.c Sat Oct 9 01:44:14 1999 @@ -87,6 +87,7 @@ typedef struct { int enabled; + int checkspellingwithreferer; } spconfig; /* @@ -103,6 +104,7 @@ spconfig *cfg = ap_pcalloc(p, sizeof(spconfig)); cfg->enabled = 0; + cfg->checkspellingwithreferer = 1; return cfg; } @@ -124,24 +126,17 @@ } /* - * Handler for the CheckSpelling directive, which is FLAG. - */ -static const char *set_speling(cmd_parms *cmd, void *mconfig, int arg) -{ - spconfig *cfg = (spconfig *) mconfig; - - cfg->enabled = arg; - return NULL; -} - -/* * Define the directives specific to this module. This structure is referenced * later by the 'module' structure. */ static const command_rec speling_cmds[] = { - { "CheckSpelling", set_speling, NULL, OR_OPTIONS, FLAG, + { "CheckSpelling", ap_set_flag_slot, + (void *) XtOffsetOf(spconfig, enabled), OR_OPTIONS, FLAG, "whether or not to fix miscapitalized/misspelled requests" }, + { "CheckSpellingWithReferer", ap_set_flag_slot, (void *) XtOffsetOf( + spconfig, checkspellingwithreferer), OR_OPTIONS, FLAG, + "Check spelling even if the request contains a Referer-header (ie. the user followed a link)" }, { NULL } }; @@ -224,6 +219,30 @@ - (int) (((misspelled_file *) rite)->quality); } +/* + * Code borrowed from mod_rewrite + * Does more then necessary but it works(tm) + */ +static char *lookup_header(request_rec *r, const char *name) +{ + array_header *hdrs_arr; + table_entry *hdrs; + int i; + + hdrs_arr = ap_table_elts(r->headers_in); + hdrs = (table_entry *)hdrs_arr->elts; + for (i = 0; i < hdrs_arr->nelts; ++i) { + if (hdrs[i].key == NULL) { + continue; + } + if (strcasecmp(hdrs[i].key, name) == 0) { + return hdrs[i].val; + } + } + return NULL; +} + + static int check_speling(request_rec *r) { spconfig *cfg; @@ -243,6 +262,11 @@ return DECLINED; } + /* If CheckSpellingWithReferer is off, check for "Referer" */ + if (!cfg->checkspellingwithreferer && lookup_header(r, "Referer")) { + return DECLINED; + } + /* We've already got a file of some kind or another */ if (r->proxyreq || (r->finfo.st_mode != 0)) { return DECLINED;