Feature #2085
closednull redirects for mod_redirect
Description
Please add null-redirects to mod_redirect. In other words, a pattern which, when matched, does nothing, not even a redirect back to the same address (which is pointless anyway). Supplied is a patch which implements this using the syntax
"pattern" => ""
Presumably, no-one is using the value "" as the target for a redirect, so this should not disrupt existing systems.
This would be helpful in defining exceptions to global redirect rules. Say you want to redirect all HTTPS traffic to HTTP, except for a few special pages, and you want this to be flexible. Then you can define the exceptions (eg. with var.redirect_exceptions += ( "pattern" => "" ) ) in several multiple include files, with the last include file defining the global redirect rule.
Files
Updated by gstrauss over 8 years ago
Trivial patch, but the question is whether it should be done or not. Also, should something similar be done in mod_rewrite?
Updated by gstrauss over 8 years ago
mod_rewrite documents:
https://redmine.lighttpd.net/projects/lighttpd/wiki/docs_modrewrite
However, mod_rewrite provides a mechanism to pass URLs through unmangled: specify "$0" as the rule target.
Updated by gstrauss over 8 years ago
- Status changed from New to Patch Pending
- Target version set to 1.4.40
@qqqqq's one-line patch provides a "match and no-op" feature to mod_redirect which short-circuits and does not match further redirect rules.
While a $HTTP["url"] condition with a negative match could be used to avoid applying a set of generic redirect rules, the admin would have to collect all those exception paths into a single condition, or else would have to repeat redirect rules.
The "match and no-op" solution provides a more convenient short-circuit to ignore further redirect rules.
Updated by gstrauss over 8 years ago
Updated patch to match target pattern against "$0" and short-circuit since it is 'identity' pattern, similar to mod_rewrite.
diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 5e99dcb..d79403e 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -209,6 +209,10 @@ static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_ "execution error while matching: ", n); return HANDLER_ERROR; } + } else if (2 == pattern_len && pattern[0] == '$' && pattern[1] == '0') { + /* short-circuit if "$0" replacement pattern (identity) + * (do not attempt to match against remaining redirect rules) */ + return HANDLER_GO_ON; } else { const char **list; size_t start;
Updated by stbuehler over 8 years ago
gstrauss wrote:
mod_rewrite documents:
https://redmine.lighttpd.net/projects/lighttpd/wiki/docs_modrewriteHowever, mod_rewrite provides a mechanism to pass URLs through unmangled: specify "$0" as the rule target.
That is actually not true (don't know who wrote that piece): "$0" is the complete match, but if you didn't match the complete input, it doesn't return the "unmangled" input.
Updated by gstrauss over 8 years ago
Does that mean you would prefer the solution originally presented, which is a blank target pattern?
Updated by stbuehler over 8 years ago
A blank target doesn't have any sane semantic so far, so I see no problem using it for a special purpose. Maybe the same pattern could then also be applied to mod_rewrite for consistency.
Updated by gstrauss over 8 years ago
Thanks.
Simple modification to the patch. I'll look at mod_rewrite next.
diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 5e99dcb..d79403e 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -209,6 +209,10 @@ static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_ "execution error while matching: ", n); return HANDLER_ERROR; } + } else if (0 == pattern_len) { + /* short-circuit if blank replacement pattern + * (do not attempt to match against remaining redirect rules) */ + return HANDLER_GO_ON; } else { const char **list; size_t start;
Updated by gstrauss over 8 years ago
Similar change to add this feature to mod_rewrite:
diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index fac6c49..faa7f84 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -383,6 +383,10 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data "execution error while matching: ", n); return HANDLER_ERROR; } + } else if (0 == pattern_len) { + /* short-circuit if blank replacement pattern + * (do not attempt to match against remaining rewrite rules) */ + return HANDLER_GO_ON; } else { const char **list; size_t start;
Updated by gstrauss over 8 years ago
- Status changed from Patch Pending to Fixed
Also available in: Atom