httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@engelschall.com (Ralf S. Engelschall)
Subject [PATCH] mod_rewrite: fixed redirects
Date Tue, 15 Apr 1997 16:12:00 GMT

Below is a patch for mod_rewrite which 

1. fixes HTTP redirects from within .htaccess files.
   The RewriteBase was not replaced correctly
   due to a nasty for-loop bug. Now 
      RewriteEngine on
	  RewriteBase   /~coar
	  RewriteRule   ^FOO$  BAR [R]
   will also work for you, Ken ;-)

2. fixes some typos in the comments.  Because english is not my native
   language I have a lot of words which I always ;-) write false (like
   "allways").

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

*** mod_rewrite.c.orig	Tue Apr  8 09:10:37 1997
--- mod_rewrite.c	Tue Apr 15 18:00:47 1997
***************
*** 61,67 ****
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.3 (08-Apr-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 
--- 61,67 ----
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.4 (15-Apr-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 
***************
*** 143,149 ****
  **  o  the order of modules at (**) is the inverted order as
  **     given in the "Configuration" file, i.e. the last module
  **     specified is the first one called for each hook!
! **     The core module is allways the last!
  **
  **  o  there are two different types of result checking and 
  **     continue processing:
--- 143,149 ----
  **  o  the order of modules at (**) is the inverted order as
  **     given in the "Configuration" file, i.e. the last module
  **     specified is the first one called for each hook!
! **     The core module is always the last!
  **
  **  o  there are two different types of result checking and 
  **     continue processing:
***************
*** 155,165 ****
  **     for hook #2,#3,#7,#9:
  **         all hooks are run, independend of result
  **
! **  o  at the last stage, the core module allways 
  **       - says "BAD_REQUEST" if r->filename does not begin with "/"
  **       - prefix URL with document_root or replaced server_root
  **         with document_root and sets r->filename
! **       - allways return a "OK" independed if the file really exists
  **         or not!
  **
  */
--- 155,165 ----
  **     for hook #2,#3,#7,#9:
  **         all hooks are run, independend of result
  **
! **  o  at the last stage, the core module always 
  **       - says "BAD_REQUEST" if r->filename does not begin with "/"
  **       - prefix URL with document_root or replaced server_root
  **         with document_root and sets r->filename
! **       - always return a "OK" independed if the file really exists
  **         or not!
  **
  */
***************
*** 948,955 ****
              /* skip 'scheme:' */
              for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                  ;
!             /* skip '//' */
!             cp += 2;
              /* skip host part */
              for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
--- 948,955 ----
              /* skip 'scheme:' */
              for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                  ;
!             /* skip '://' */
!             cp += 3;
              /* skip host part */
              for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
***************
*** 992,998 ****
              /* Hack because of underpowered API: passing the current
                 rewritten filename through to other URL-to-filename handlers
                 just as it were the requested URL. This is to enable
!                post-processing by mod_alias, etc.  which allways act on
                 r->uri! The difference here is: We do not try to
                 add the document root */
              r->uri = pstrdup(r->pool, r->filename+12);
--- 992,998 ----
              /* Hack because of underpowered API: passing the current
                 rewritten filename through to other URL-to-filename handlers
                 just as it were the requested URL. This is to enable
!                post-processing by mod_alias, etc.  which always act on
                 r->uri! The difference here is: We do not try to
                 add the document root */
              r->uri = pstrdup(r->pool, r->filename+12);
***************
*** 1036,1042 ****
                      strncpy(docroot, cp, sizeof(docroot)-1);
                      EOS_PARANOIA(docroot);
  
!                     /* allways NOT have a trailing slash */
                      l = strlen(docroot);
                      if (docroot[l-1] == '/') {
                          docroot[l-1] = '\0';
--- 1036,1042 ----
                      strncpy(docroot, cp, sizeof(docroot)-1);
                      EOS_PARANOIA(docroot);
  
!                     /* always NOT have a trailing slash */
                      l = strlen(docroot);
                      if (docroot[l-1] == '/') {
                          docroot[l-1] = '\0';
***************
*** 1176,1183 ****
                  /* skip 'scheme:' */
                  for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                      ;
!                 /* skip '//' */
!                 cp += 2;
                  if ((cp = strchr(cp, '/')) != NULL) {
                      rewritelog(r, 2, "[per-dir %s] trying to replace prefix %s with %s",
dconf->directory, dconf->directory, dconf->baseurl);
                      cp2 = subst_prefix_path(r, cp, dconf->directory, dconf->baseurl);
--- 1176,1183 ----
                  /* skip 'scheme:' */
                  for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                      ;
!                 /* skip '://' */
!                 cp += 3;
                  if ((cp = strchr(cp, '/')) != NULL) {
                      rewritelog(r, 2, "[per-dir %s] trying to replace prefix %s with %s",
dconf->directory, dconf->directory, dconf->baseurl);
                      cp2 = subst_prefix_path(r, cp, dconf->directory, dconf->baseurl);
***************
*** 1193,1200 ****
              /* skip 'scheme:' */
              for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                  ;
!             /* skip '//' */
!             cp += 2;
              /* skip host part */
              for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
--- 1193,1200 ----
              /* skip 'scheme:' */
              for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
                  ;
!             /* skip '://' */
!             cp += 3;
              /* skip host part */
              for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
***************
*** 1264,1270 ****
  
                  if ((cp = document_root(r)) != NULL) {
                      prefix = pstrdup(r->pool, cp);
!                     /* allways NOT have a trailing slash */
                      l = strlen(prefix);
                      if (prefix[l-1] == '/') {
                          prefix[l-1] = '\0';
--- 1264,1270 ----
  
                  if ((cp = document_root(r)) != NULL) {
                      prefix = pstrdup(r->pool, cp);
!                     /* always NOT have a trailing slash */
                      l = strlen(prefix);
                      if (prefix[l-1] == '/') {
                          prefix[l-1] = '\0';
***************
*** 2873,2888 ****
  
      output = input;
  
!     /* first, remove the local directory prefix */
      strncpy(matchbuf, match, sizeof(matchbuf)-1);
      EOS_PARANOIA(matchbuf);
-     /* allways have a trailing slash */
      l = strlen(matchbuf);
      if (matchbuf[l-1] != '/') {
         matchbuf[l] = '/';
         matchbuf[l+1] = '\0';
         l++;
      }
      if (strncmp(input, matchbuf, l) == 0) {
          rewritelog(r, 5, "strip matching prefix: %s -> %s", output, output+l);
          output = pstrdup(r->pool, output+l); 
--- 2873,2888 ----
  
      output = input;
  
!     /* first create a match string which always has a trailing slash */
      strncpy(matchbuf, match, sizeof(matchbuf)-1);
      EOS_PARANOIA(matchbuf);
      l = strlen(matchbuf);
      if (matchbuf[l-1] != '/') {
         matchbuf[l] = '/';
         matchbuf[l+1] = '\0';
         l++;
      }
+     /* now compare the prefix */
      if (strncmp(input, matchbuf, l) == 0) {
          rewritelog(r, 5, "strip matching prefix: %s -> %s", output, output+l);
          output = pstrdup(r->pool, output+l); 
***************
*** 2890,2896 ****
          /* and now add the base-URL as replacement prefix */
          strncpy(substbuf, subst, sizeof(substbuf)-1);
          EOS_PARANOIA(substbuf);
-         /* allways have a trailing slash */
          l = strlen(substbuf);
          if (substbuf[l-1] != '/') {
             substbuf[l] = '/';
--- 2890,2895 ----
*** mod_rewrite.h.orig	Tue Apr  8 08:12:26 1997
--- mod_rewrite.h	Tue Apr 15 17:57:01 1997
***************
*** 64,70 ****
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.3 (04-Apr-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 
--- 64,70 ----
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.4 (17-Apr-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 

Mime
View raw message