📄 mod_rewrite.c
字号:
sconf->state = (flag ? ENGINE_ENABLED : ENGINE_DISABLED); } else /* is per-directory command */ { dconf->state = (flag ? ENGINE_ENABLED : ENGINE_DISABLED); } return NULL;}static const char *cmd_rewriteoptions(cmd_parms *cmd, rewrite_perdir_conf *dconf, char *option){ rewrite_server_conf *sconf; const char *err; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); if (cmd->path == NULL) { /* is server command */ err = cmd_rewriteoptions_setoption(cmd->pool, &(sconf->options), option); } else { /* is per-directory command */ err = cmd_rewriteoptions_setoption(cmd->pool, &(dconf->options), option); } return err;}static const char *cmd_rewriteoptions_setoption(pool *p, int *options, char *name){ if (strcasecmp(name, "inherit") == 0) { *options |= OPTION_INHERIT; } else { return ap_pstrcat(p, "RewriteOptions: unknown option '", name, "'\n", NULL); } return NULL;}static const char *cmd_rewritelog(cmd_parms *cmd, void *dconf, char *a1){ rewrite_server_conf *sconf; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); sconf->rewritelogfile = a1; return NULL;}static const char *cmd_rewriteloglevel(cmd_parms *cmd, void *dconf, char *a1){ rewrite_server_conf *sconf; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); sconf->rewriteloglevel = atoi(a1); return NULL;}static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, char *a1, char *a2){ rewrite_server_conf *sconf; rewritemap_entry *new; struct stat st; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); new = ap_push_array(sconf->rewritemaps); new->name = a1; new->func = NULL; if (strncmp(a2, "txt:", 4) == 0) { new->type = MAPTYPE_TXT; new->datafile = a2+4; new->checkfile = a2+4; } else if (strncmp(a2, "rnd:", 4) == 0) { new->type = MAPTYPE_RND; new->datafile = a2+4; new->checkfile = a2+4; } else if (strncmp(a2, "dbm:", 4) == 0) {#ifndef NO_DBM_REWRITEMAP new->type = MAPTYPE_DBM; new->datafile = a2+4; new->checkfile = ap_pstrcat(cmd->pool, a2+4, NDBM_FILE_SUFFIX, NULL);#else return ap_pstrdup(cmd->pool, "RewriteMap: cannot use NDBM mapfile, " "because no NDBM support is compiled in");#endif } else if (strncmp(a2, "prg:", 4) == 0) { new->type = MAPTYPE_PRG; new->datafile = a2+4; new->checkfile = a2+4; } else if (strncmp(a2, "int:", 4) == 0) { new->type = MAPTYPE_INT; new->datafile = NULL; new->checkfile = NULL; if (strcmp(a2+4, "tolower") == 0) { new->func = rewrite_mapfunc_tolower; } else if (strcmp(a2+4, "toupper") == 0) { new->func = rewrite_mapfunc_toupper; } else if (sconf->state == ENGINE_ENABLED) { return ap_pstrcat(cmd->pool, "RewriteMap: internal map not found:", a2+4, NULL); } } else { new->type = MAPTYPE_TXT; new->datafile = a2; new->checkfile = a2; } new->fpin = -1; new->fpout = -1; if (new->checkfile && (sconf->state == ENGINE_ENABLED) && (stat(new->checkfile, &st) == -1)) { return ap_pstrcat(cmd->pool, "RewriteMap: map file or program not found:", new->checkfile, NULL); } return NULL;}static const char *cmd_rewritelock(cmd_parms *cmd, void *dconf, char *a1){ rewrite_server_conf *sconf; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); sconf->rewritelockfile = a1; return NULL;}static const char *cmd_rewritebase(cmd_parms *cmd, rewrite_perdir_conf *dconf, char *a1){ if (cmd->path == NULL || dconf == NULL) { return "RewriteBase: only valid in per-directory config files"; } if (a1[0] == '\0') { return "RewriteBase: empty URL not allowed"; } if (a1[0] != '/') { return "RewriteBase: argument is not a valid URL"; } dconf->baseurl = a1; return NULL;}static const char *cmd_rewritecond(cmd_parms *cmd, rewrite_perdir_conf *dconf, char *str){ rewrite_server_conf *sconf; rewritecond_entry *new; regex_t *regexp; char *a1; char *a2; char *a3; char *cp; const char *err; int rc; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); /* make a new entry in the internal temporary rewrite rule list */ if (cmd->path == NULL) { /* is server command */ new = ap_push_array(sconf->rewriteconds); } else { /* is per-directory command */ new = ap_push_array(dconf->rewriteconds); } /* parse the argument line ourself */ if (parseargline(str, &a1, &a2, &a3)) { return ap_pstrcat(cmd->pool, "RewriteCond: bad argument line '", str, "'\n", NULL); } /* arg1: the input string */ new->input = ap_pstrdup(cmd->pool, a1); /* arg3: optional flags field (this have to be first parsed, because we need to know if the regex should be compiled with ICASE!) */ new->flags = CONDFLAG_NONE; if (a3 != NULL) { if ((err = cmd_rewritecond_parseflagfield(cmd->pool, new, a3)) != NULL) { return err; } } /* arg2: the pattern try to compile the regexp to test if is ok */ cp = a2; if (cp[0] == '!') { new->flags |= CONDFLAG_NOTMATCH; cp++; } /* now be careful: Under the POSIX regex library we can compile the pattern for case-insensitive matching, under the old V8 library we have to do it self via a hack */ if (new->flags & CONDFLAG_NOCASE) { rc = ((regexp = ap_pregcomp(cmd->pool, cp, REG_EXTENDED|REG_ICASE)) == NULL); } else { rc = ((regexp = ap_pregcomp(cmd->pool, cp, REG_EXTENDED)) == NULL); } if (rc) { return ap_pstrcat(cmd->pool, "RewriteCond: cannot compile regular expression '", a2, "'\n", NULL); } new->pattern = ap_pstrdup(cmd->pool, cp); new->regexp = regexp; return NULL;}static const char *cmd_rewritecond_parseflagfield(pool *p, rewritecond_entry *cfg, char *str){ char *cp; char *cp1; char *cp2; char *cp3; char *key; char *val; const char *err; if (str[0] != '[' || str[strlen(str)-1] != ']') { return "RewriteCond: bad flag delimiters"; } cp = str+1; str[strlen(str)-1] = ','; /* for simpler parsing */ for ( ; *cp != '\0'; ) { /* skip whitespaces */ for ( ; (*cp == ' ' || *cp == '\t') && *cp != '\0'; cp++) ; if (*cp == '\0') { break; } cp1 = cp; if ((cp2 = strchr(cp, ',')) != NULL) { cp = cp2+1; for ( ; (*(cp2-1) == ' ' || *(cp2-1) == '\t'); cp2--) ; *cp2 = '\0'; if ((cp3 = strchr(cp1, '=')) != NULL) { *cp3 = '\0'; key = cp1; val = cp3+1; } else { key = cp1; val = ""; } if ((err = cmd_rewritecond_setflag(p, cfg, key, val)) != NULL) { return err; } } else { break; } } return NULL;}static const char *cmd_rewritecond_setflag(pool *p, rewritecond_entry *cfg, char *key, char *val){ if ( strcasecmp(key, "nocase") == 0 || strcasecmp(key, "NC") == 0 ) { cfg->flags |= CONDFLAG_NOCASE; } else if ( strcasecmp(key, "ornext") == 0 || strcasecmp(key, "OR") == 0 ) { cfg->flags |= CONDFLAG_ORNEXT; } else { return ap_pstrcat(p, "RewriteCond: unknown flag '", key, "'\n", NULL); } return NULL;}static const char *cmd_rewriterule(cmd_parms *cmd, rewrite_perdir_conf *dconf, char *str){ rewrite_server_conf *sconf; rewriterule_entry *new; regex_t *regexp; char *a1; char *a2; char *a3; char *cp; const char *err; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); /* make a new entry in the internal rewrite rule list */ if (cmd->path == NULL) { /* is server command */ new = ap_push_array(sconf->rewriterules); } else { /* is per-directory command */ new = ap_push_array(dconf->rewriterules); } /* parse the argument line ourself */ if (parseargline(str, &a1, &a2, &a3)) { return ap_pstrcat(cmd->pool, "RewriteRule: bad argument line '", str, "'\n", NULL); } /* 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) { return ap_pstrcat(cmd->pool, "RewriteRule: cannot compile regular expression '", a1, "'\n", NULL); } new->pattern = ap_pstrdup(cmd->pool, cp); new->regexp = regexp; /* arg2: the output string * replace the $<N> by \<n> which is needed by the currently * used Regular Expression library */ 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 */ if (cmd->path == NULL) { /* is server command */ new->rewriteconds = sconf->rewriteconds; sconf->rewriteconds = ap_make_array(cmd->pool, 2, sizeof(rewritecond_entry)); } else { /* is per-directory command */ new->rewriteconds = dconf->rewriteconds;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -