cookie set with "NAME=value". You have to clear the cookie "NAME=" for
that, because the browser makes the difference.
+ - "keep-query"
+ When this keyword is used in a location-based redirection, then the
+ query-string of the original URI, if any, will be appended to the
+ location. If no query-string is found, nothing is added. If the
+ location already contains a query-string, the original one will be
+ appended with the '&' delimiter.
+
+
Example: move the login URL only to HTTPS.
acl clear dst_port 80
acl secure dst_port 8080
REDIRECT_FLAG_APPEND_SLASH = 2, /* append a slash if missing at the end */
REDIRECT_FLAG_FROM_REQ = 4, /* redirect rule on the request path */
REDIRECT_FLAG_IGNORE_EMPTY = 8, /* silently ignore empty location expressions */
+ REDIRECT_FLAG_KEEP_QS = 16, /* append the query string to location, if any */
};
/* Redirect types (location, prefix, extended ) */
}
case REDIRECT_TYPE_LOCATION:
default:
+ memset(chunk->area, 0x50, chunk->size);
if (rule->rdr_str) { /* this is an old "redirect" rule */
/* add location */
if (!chunk_memcat(chunk, rule->rdr_str, rule->rdr_len))
chunk->data += len;
}
+
+ if (rule->flags & REDIRECT_FLAG_KEEP_QS) {
+ struct ist path;
+ struct http_uri_parser parser;
+ char *ptr, *end;
+ char sep = '?';
+
+ ptr = memchr(chunk->area, '?', chunk->data);
+ if (ptr != NULL)
+ sep = ((ptr+1 != b_tail(chunk)) ? '&' : '\0');
+
+ sl = http_get_stline(htx);
+ parser = http_uri_parser_init(htx_sl_req_uri(sl));
+ path = http_parse_path(&parser);
+ ptr = istptr(path);
+ end = istend(path);
+
+ /* look up the '?' */
+ do {
+ if (ptr == end)
+ return 0;
+ } while (*ptr++ != '?');
+
+ if (ptr == end)
+ break;
+ if (sep != '\0' && !chunk_memcat(chunk, &sep, 1))
+ goto fail;
+ if (!chunk_memcat(chunk, ptr, end-ptr))
+ goto fail;
+ }
break;
}
location = ist2(chunk->area, chunk->data);
else if (strcmp(args[cur_arg], "drop-query") == 0) {
flags |= REDIRECT_FLAG_DROP_QS;
}
+ else if (strcmp(args[cur_arg], "keep-query") == 0) {
+ flags |= REDIRECT_FLAG_KEEP_QS;
+ }
else if (strcmp(args[cur_arg], "append-slash") == 0) {
flags |= REDIRECT_FLAG_APPEND_SLASH;
}
}
else {
memprintf(errmsg,
- "expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query', 'ignore-empty' or 'append-slash' (was '%s')",
+ "expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query', 'keep-query', 'ignore-empty' or 'append-slash' (was '%s')",
args[cur_arg]);
goto err;
}