Project

General

Profile

Actions

Feature #2085

closed

null redirects for mod_redirect

Added by qqqqq over 14 years ago. Updated almost 8 years ago.

Status:
Fixed
Priority:
Normal
Category:
mod_redirect
Target version:
ASK QUESTIONS IN Forums:

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

null_redirect.diff (591 Bytes) null_redirect.diff patch on trunk @ 2009-10-18T16:15:00+0100 qqqqq, 2009-10-18 15:17
Actions #1

Updated by qqqqq over 14 years ago

  • Target version set to 1.4.x
Actions #2

Updated by qqqqq over 14 years ago

  • Target version deleted (1.4.x)
Actions #3

Updated by gstrauss about 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?

Actions #4

Updated by gstrauss almost 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.

Actions #5

Updated by gstrauss almost 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.

Actions #6

Updated by gstrauss almost 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;
Actions #7

Updated by stbuehler almost 8 years ago

gstrauss wrote:

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.

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.

Actions #8

Updated by gstrauss almost 8 years ago

Does that mean you would prefer the solution originally presented, which is a blank target pattern?

Actions #9

Updated by stbuehler almost 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.

Actions #10

Updated by gstrauss almost 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;
Actions #11

Updated by gstrauss almost 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;

Actions #12

Updated by gstrauss almost 8 years ago

  • Status changed from Patch Pending to Fixed
Actions

Also available in: Atom