You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1997/03/15 14:18:06 UTC

[SYNC] mod_rewrite

The below context diff updates the current CVS version of mod_rewrite to my
author version. Changes are

   - a kludge to make mod_rewrite compilable under AIX which
     needs fcntl instead of flock

     [causes no problems] 

   - improvements to the redirection stuff to enable the users to generally
     redirect to http, https, gopher and ftp. This is the result of a problem
     dicussion on c.i.w.s.u. This also provides the power to realise access
     multiplexers like http://www.perl.com/CPAN directly with mod_rewrite.

     [I've tested it with per-server and per-directory redirects
      and worked correct but this one should be reviewed]

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

*** mod_rewrite.h.old	Sat Feb 22 03:00:16 1997
--- mod_rewrite.h	Sat Mar 15 13:48:34 1997
***************
*** 64,70 ****
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.0 (01-02-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.0 (15-Mar-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 
***************
*** 110,117 ****
  
  
      /* The locking support:
!        Try to determine whether we should use
!        fcntl() or flock(). */
  #if defined(USE_FCNTL_SERIALIZED_ACCEPT)
  #define USE_FCNTL 1
  #include <fcntl.h>
--- 110,117 ----
  
  
      /* The locking support:
!        Try to determine whether we should use fcntl() or flock().
!        Would be better conf.h could provide this... :-( */
  #if defined(USE_FCNTL_SERIALIZED_ACCEPT)
  #define USE_FCNTL 1
  #include <fcntl.h>
***************
*** 130,135 ****
--- 130,140 ----
  #define USE_FCNTL 1
  #include <fcntl.h>
  #endif
+ #endif
+ #ifdef AIX
+ #undef USE_FLOCK
+ #define USE_FCNTL 1
+ #include <fcntl.h>
  #endif
  
  
*** mod_rewrite.c.old	Fri Mar  7 15:00:11 1997
--- mod_rewrite.c	Sat Mar 15 13:23:48 1997
***************
*** 61,67 ****
  **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
  **                       |_____|
  **
! **  URL Rewriting Module, Version 3.0.0 (06-Mar-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.0 (15-Mar-1997)
  **
  **  This module uses a rule-based rewriting engine (based on a
  **  regular-expression parser) to rewrite requested URLs on the fly. 
***************
*** 935,958 ****
              rewritelog(r, 1, "go-ahead with proxy request %s [OK]", r->filename);
              return OK; 
          }
! #ifdef APACHE_SSL
!         else if (  (!r->connection->client->ssl &&
!                     strlen(r->filename) > 7     &&
                      strncmp(r->filename, "http://", 7) == 0)
!                 || (r->connection->client->ssl  &&
!                     strlen(r->filename) > 8     &&
!                     strncmp(r->filename, "https://", 8) == 0) ) {
! #else
!         else if (strlen(r->filename) > 7 &&
!                  strncmp(r->filename, "http://", 7) == 0) {
! #endif
!             /* it was finally rewritten to a remote path */
  
! #ifdef APACHE_SSL
!             for (cp = r->filename+strlen(http_method(r))+3; *cp != '/' && *cp != '\0'; cp++)
! #else
!             for (cp = r->filename+7; *cp != '/' && *cp != '\0'; cp++)
! #endif
                  ;
              if (*cp != '\0') {
                  rewritelog(r, 1, "escaping %s for redirect", r->filename);
--- 935,957 ----
              rewritelog(r, 1, "go-ahead with proxy request %s [OK]", r->filename);
              return OK; 
          }
!         else if (  (strlen(r->filename) > 7 &&
                      strncmp(r->filename, "http://", 7) == 0)
!                 || (strlen(r->filename) > 8 &&
!                     strncmp(r->filename, "https://", 8) == 0)
!                 || (strlen(r->filename) > 9 &&
!                     strncmp(r->filename, "gopher://", 9) == 0)
!                 || (strlen(r->filename) > 6 &&
!                     strncmp(r->filename, "ftp://", 6) == 0)    ) {
!             /* it was finally rewritten to a remote URL */
  
!             /* skip 'scheme:' */
!             for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
!                 ;
!             /* skip '//' */
!             cp += 2;
!             /* skip host part */
!             for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
              if (*cp != '\0') {
                  rewritelog(r, 1, "escaping %s for redirect", r->filename);
***************
*** 1160,1187 ****
              rewritelog(r, 1, "[per-dir %s] go-ahead with proxy request %s [OK]", dconf->directory, r->filename);
              return OK; 
          }
! #ifdef APACHE_SSL
!         else if (  (!r->connection->client->ssl &&
!                     strlen(r->filename) > 7     &&
                      strncmp(r->filename, "http://", 7) == 0)
!                 || (r->connection->client->ssl  &&
!                     strlen(r->filename) > 8     &&
!                     strncmp(r->filename, "https://", 8) == 0) ) {
! #else
!         else if (strlen(r->filename) > 7 &&
!                  strncmp(r->filename, "http://", 7) == 0) {
! #endif
!             /* it was finally rewritten to a remote path */
  
              /* because we are in a per-dir context
                 first try to replace the directory with its base-URL
                 if there is a base-URL available */
              if (dconf->baseurl != NULL) {
! #ifdef APACHE_SSL
!                 if ((cp = strchr(r->filename+strlen(http_method(r))+3, '/')) != NULL) {
! #else
!                 if ((cp = strchr(r->filename+7, '/')) != NULL) {
! #endif
                      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);
                      if (strcmp(cp2, cp) != 0) {
--- 1159,1184 ----
              rewritelog(r, 1, "[per-dir %s] go-ahead with proxy request %s [OK]", dconf->directory, r->filename);
              return OK; 
          }
!         else if (  (strlen(r->filename) > 7 &&
                      strncmp(r->filename, "http://", 7) == 0)
!                 || (strlen(r->filename) > 8 &&
!                     strncmp(r->filename, "https://", 8) == 0)
!                 || (strlen(r->filename) > 9 &&
!                     strncmp(r->filename, "gopher://", 9) == 0)
!                 || (strlen(r->filename) > 6 &&
!                     strncmp(r->filename, "ftp://", 6) == 0)    ) {
!             /* it was finally rewritten to a remote URL */
  
              /* because we are in a per-dir context
                 first try to replace the directory with its base-URL
                 if there is a base-URL available */
              if (dconf->baseurl != NULL) {
!                 /* 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);
                      if (strcmp(cp2, cp) != 0) {
***************
*** 1192,1202 ****
              }
  
              /* now prepare the redirect... */
! #ifdef APACHE_SSL
!             for (cp = r->filename+strlen(http_method(r))+3; *cp != '/' && *cp != '\0'; cp++)
! #else
!             for (cp = r->filename+7; *cp != '/' && *cp != '\0'; cp++)
! #endif
                  ;
              if (*cp != '\0') {
                  rewritelog(r, 1, "[per-dir %s] escaping %s for redirect", dconf->directory, r->filename);
--- 1189,1202 ----
              }
  
              /* now prepare the redirect... */
! 
!             /* skip 'scheme:' */
!             for (cp = r->filename; *cp != ':' && *cp != '\0'; cp++)
!                 ;
!             /* skip '//' */
!             cp += 2;
!             /* skip host part */
!             for ( ; *cp != '/' && *cp != '\0'; cp++)
                  ;
              if (*cp != '\0') {
                  rewritelog(r, 1, "[per-dir %s] escaping %s for redirect", dconf->directory, r->filename);
***************
*** 1523,1536 ****
          }
  
          /* if this is a implicit redirect in a per-dir rule */
! #ifdef APACHE_SSL
!         if (perdir != NULL && (  (!r->connection->client->ssl &&
!                                   strncmp(output, "http://", 7) == 0)
!                               || (r->connection->client->ssl &&
!                                   strncmp(output, "https://", 8) == 0) )) { 
! #else
!         if (perdir != NULL && strncmp(output, "http://", 7) == 0) {
! #endif
              if (p->flags & RULEFLAG_NOTMATCH) {
                  strncpy(newuri, output, sizeof(newuri)-1);
                  EOS_PARANOIA(newuri);
--- 1523,1534 ----
          }
  
          /* if this is a implicit redirect in a per-dir rule */
!         i = strlen(output);
!         if (perdir != NULL
!             && (   (i > 7 && strncmp(output, "http://", 7) == 0)
!                 || (i > 8 && strncmp(output, "https://", 8) == 0)
!                 || (i > 9 && strncmp(output, "gopher://", 9) == 0)
!                 || (i > 6 && strncmp(output, "ftp://", 6) == 0)   ) ) {
              if (p->flags & RULEFLAG_NOTMATCH) {
                  strncpy(newuri, output, sizeof(newuri)-1);
                  EOS_PARANOIA(newuri);
***************
*** 1591,1597 ****
  
          r->filename = pstrdup(r->pool, newuri);
  
!         /* reduce http://<ourhost>[:<port>] */
          reduce_uri(r);
  
          /* split out on-the-fly generated QUERY_STRING '....?xxxxx&xxxx...' */
--- 1589,1595 ----
  
          r->filename = pstrdup(r->pool, newuri);
  
!         /* reduce http[s]://<ourhost>[:<port>] */
          reduce_uri(r);
  
          /* split out on-the-fly generated QUERY_STRING '....?xxxxx&xxxx...' */
***************
*** 1607,1622 ****
          }
  
          /* if we are forced to do a explicit redirect by [R] flag
!            finally prefix the new URI with http://<ourname> explicitly */
          if (flags & RULEFLAG_FORCEREDIRECT) {
! #ifdef APACHE_SSL
!            if ( (!r->connection->client->ssl &&
!                  strncmp(r->filename, "http://", 7) != 0) ||
!                 (r->connection->client->ssl &&
!                  strncmp(r->filename, "https://", 8) != 0)) {
! #else
!             if (strncmp(r->filename, "http://", 7) != 0) {
! #endif
  #ifdef APACHE_SSL
                  if ((!r->connection->client->ssl && r->server->port == 80) ||
                      ( r->connection->client->ssl && r->server->port == 443)  )
--- 1605,1622 ----
          }
  
          /* if we are forced to do a explicit redirect by [R] flag
!            and the current URL still is not a fully qualified one we
!            finally prefix it with http[s]://<ourname> explicitly */
          if (flags & RULEFLAG_FORCEREDIRECT) {
!             if (  !(strlen(r->filename) > 7 &&
!                     strncmp(r->filename, "http://", 7) == 0)
!                && !(strlen(r->filename) > 8 &&
!                     strncmp(r->filename, "https://", 8) == 0)
!                && !(strlen(r->filename) > 9 &&
!                     strncmp(r->filename, "gopher://", 9) == 0)
!                && !(strlen(r->filename) > 6 &&
!                     strncmp(r->filename, "ftp://", 6) == 0)    ) {
! 
  #ifdef APACHE_SSL
                  if ((!r->connection->client->ssl && r->server->port == 80) ||
                      ( r->connection->client->ssl && r->server->port == 443)  )
***************
*** 1790,1796 ****
  
  /*
  **
! **  strip 'http://ourhost/' from URI
  **
  */
  
--- 1790,1796 ----
  
  /*
  **
! **  strip 'http[s]://ourhost/' from URI
  **
  */