httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andrea rossignoli <apachel...@libero.it>
Subject Added an env var to mod_rewrite
Date Tue, 30 Sep 2003 12:33:07 GMT
Hi,

in some situations it could be good to read the value on the internal 
redirect counter of mod_rewrite.

Take a look at this scenario:

/.htaccess
----
RewriteEngine On

# If there are not internal redirects
# ( e.g. the redirects counter is zero )
# then denies accesses to secret/ subdirectory
RewriteCond %{REWRITE_REDIRECTS} ^0$
RewriteRule ^secret/ - [F,L]

# Internally redirect to secret script
RewriteRule ^something$ /secret/order.php
----

THe accesses to secret subdirectory are denied,
except when an internal redirection is done.

OKay, maybe the example is not self-good.

I took a look at mod_rewrite.c (release 1.3.28 for win32),
and to create an enviroment variable called ``REWRITE_REDIRECTS''
I did:



@@ -1681,6 +1681,30 @@
      return (reqc->redirects++ >= reqc->redirect_limit);
  }

+static int get_redirect_counter(request_rec *r)
+{
+    request_rec *top = r;
+    rewrite_request_conf *reqc;
+
+    while (top->main) {
+        top = top->main;
+    }
+    while (top->prev) {
+        top = top->prev;
+    }
+
+    /* fetch our config */
+    reqc = (rewrite_request_conf *) 
ap_get_module_config(top->request_config,
+                                                         &rewrite_module);
+
+    /* no config there? returns 0 */
+    if (!reqc) {
+        return 0;
+    }
+
+    return (reqc->redirects);
+}
+

  /*
  ** +-------------------------------------------------------+
@@ -3755,6 +3779,11 @@
                      MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
          result = resultbuf;
      }
+
+    else if (strcasecmp(var, "REWRITE_REDIRECTS") == 0) {
+        ap_snprintf(resultbuf, sizeof(resultbuf), "%d", 
get_redirect_counter(r));
+        result = resultbuf;
+    }

      /* underlaying Unix system stuff */
      else if (strcasecmp(var, "TIME_YEAR") == 0) {
@@ -4509,3 +4538,4 @@
  }



What do you think ?


THanks,
Mr Andrea Rossignoli


Mime
View raw message