Project

General

Profile

Feature #2085

null redirects for mod_redirect

Added by qqqqq over 7 years ago. Updated 11 months ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
mod_redirect
Target version:
Start date:
2009-10-18
Due date:
% Done:

0%

Missing in 1.5.x:
No

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.

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

Associated revisions

Revision 186e7073 (diff)
Added by gstrauss 12 months ago

[mod_redirect,mod-rewrite] short-circuit if blank replacement (fixes #2085)

x-ref:
"null redirects for mod_redirect"
https://redmine.lighttpd.net/issues/2085

History

#1 Updated by qqqqq over 7 years ago

  • Target version set to 1.4.x

#2 Updated by qqqqq over 7 years ago

  • Target version deleted (1.4.x)

#3 Updated by gstrauss 12 months ago

Trivial patch, but the question is whether it should be done or not. Also, should something similar be done in mod_rewrite?

#4 Updated by gstrauss 12 months 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.

#5 Updated by gstrauss 12 months 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.

#6 Updated by gstrauss 12 months 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;

#7 Updated by stbuehler 12 months 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.

#8 Updated by gstrauss 12 months ago

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

#9 Updated by stbuehler 12 months 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.

#10 Updated by gstrauss 12 months 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;

#11 Updated by gstrauss 12 months 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;

#12 Updated by gstrauss 11 months ago

  • Status changed from Patch Pending to Fixed

Also available in: Atom