httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Mon, 24 Feb 2003 21:55:07 GMT
nd          2003/02/24 13:55:07

  Modified:    modules/mappers mod_rewrite.c
  Log:
  This is part three.
  It fixes the misunderstandings between local URL paths and local
  system paths. Note that mod_rewrite handles _both_.
  Fixed also some comments to make the explanations more clear.
  
  Revision  Changes    Path
  1.144     +42 -11    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.143
  retrieving revision 1.144
  diff -u -r1.143 -r1.144
  --- mod_rewrite.c	24 Feb 2003 21:44:15 -0000	1.143
  +++ mod_rewrite.c	24 Feb 2003 21:55:07 -0000	1.144
  @@ -1287,8 +1287,11 @@
   #endif
               rewritelog(r, 2, "local path result: %s", r->filename);
   
  -            /* the filename must be an absolute path! */
  -            if (!ap_os_is_path_absolute(r->pool, r->filename)) {
  +            /* the filename must be either an absolute local path or an
  +             * absolute local URL.
  +             */
  +            if (   *r->filename != '/'
  +                && !ap_os_is_path_absolute(r->pool, r->filename)) {
                   return HTTP_BAD_REQUEST;
               }
   
  @@ -1483,18 +1486,43 @@
                       ;
                   /* skip '://' */
                   cp += 3;
  -                if ((cp = strchr(cp, '/')) != NULL) {
  +                if ((cp = ap_strchr(cp, '/')) != NULL && *(++cp)) {
                       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);
  +
  +                    /* I think, that hack needs an explanation:
  +                     * well, here is it:
  +                     * mod_rewrite was written for unix systems, were
  +                     * absolute file-system paths start with a slash.
  +                     * URL-paths _also_ start with slashes, so they
  +                     * can be easily compared with system paths.
  +                     *
  +                     * the following assumes, that the actual url-path
  +                     * may be prefixed by the current directory path and
  +                     * tries to replace the system path with the RewriteBase
  +                     * URL.
  +                     * That assumption is true if we use a RewriteRule like
  +                     *
  +                     * RewriteRule ^foo bar [R]
  +                     *
  +                     * (see apply_rewrite_rule function)
  +                     * However on systems that don't have a / as system
  +                     * root this will never match, so we skip the / after the
  +                     * hostname and compare/substitute only the stuff after it.
  +                     *
  +                     * (note that cp was already increased to the right value)
  +                     */
  +                    cp2 = subst_prefix_path(r, cp, (*dconf->directory == '/')
  +                                                   ? dconf->directory + 1
  +                                                   : dconf->directory,
  +                                            dconf->baseurl + 1);
                       if (strcmp(cp2, cp) != 0) {
                           *cp = '\0';
                           r->filename = apr_pstrcat(r->pool, r->filename,
  -                                                 cp2, NULL);
  +                                                  cp2, NULL);
                       }
                   }
               }
  @@ -1572,8 +1600,11 @@
                   r->filename = apr_pstrdup(r->pool, r->filename+12);
               }
   
  -            /* the filename must be an absolute path! */
  -            if (!ap_os_is_path_absolute(r->pool, r->filename)) {
  +            /* the filename must be either an absolute local path or an
  +             * absolute local URL.
  +             */
  +            if (   *r->filename != '/'
  +                && !ap_os_is_path_absolute(r->pool, r->filename)) {
                   return HTTP_BAD_REQUEST;
               }
   
  @@ -2058,12 +2089,12 @@
       splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
   
       /*
  -     *   Again add the previously stripped per-directory location
  +     *   Add the previously stripped per-directory location
        *   prefix if the new URI is not a new one for this
  -     *   location, i.e. if it's not an absolute path nor
  +     *   location, i.e. if it's not an absolute URL (!) path nor
        *   a fully qualified URL scheme.
        */
  -    if (prefixstrip && !ap_os_is_path_absolute(r->pool, r->filename)
  +    if (prefixstrip && *r->filename != '/'
                       && !is_absolute_uri(r->filename)) {
           rewritelog(r, 3, "[per-dir %s] add per-dir prefix: %s -> %s%s",
                      perdir, r->filename, perdir, r->filename);
  
  
  

Mime
View raw message