Received: (from majordom@localhost) by hyperreal.org (8.8.5/8.8.5) id IAA26697; Tue, 29 Jul 1997 08:52:39 -0700 (PDT) Received: from colin.muc.de (root@colin.muc.de [193.174.4.1]) by hyperreal.org (8.8.5/8.8.5) with SMTP id IAA26670 for ; Tue, 29 Jul 1997 08:52:32 -0700 (PDT) Received: from en by colin.muc.de with UUCP id <86097-2>; Tue, 29 Jul 1997 17:52:06 +0200 Received: by en1.engelschall.com (Sendmail 8.8.2) for new-httpd@hyperreal.org id RAA11781; Tue, 29 Jul 1997 17:51:06 +0200 (MET DST) Message-Id: <199707291551.RAA11781@en1.engelschall.com> Subject: [PATCH] more backref interpolation for rewriting engine To: new-httpd@hyperreal.org (Apache Developer ML) Date: Tue, 29 Jul 1997 17:51:05 +0200 From: rse@engelschall.com (Ralf S. Engelschall) Organization: Engelschall, Germany. X-Home: http://www.engelschall.com/ X-Mailer: ELM [version 2.4ME+ PL32 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org While the recent patches to mod_rewrite were pure bugfixes, here is an essential enhancement patch which I really want to see in 1.3. I'm myself wondering why this functionality was missing for such a long time, although is was not difficult to implement and a lot of users wanted it in the past.... Description: ------------ To make it clear, let me explain how a typical ruleset gets evaluated by the rewriting engine: RewriteCond RewriteCond : RewriteCond RewriteRule The evaluation is this: 1. Match current URL against . if not match -> ignore rule and all conditions 2. Create and match against if not match -> ignore rule and all conditions 3. Create and match against if not match -> ignore rule and all conditions : n+1. Create and match against if not match -> ignore rule and all conditions n+2. Create and replace current URL with this one. n+3. Proceed with following rules. The essential part here is that one usually uses regex grouping via parenthesis in to match some parts of the URL and then backreferences $1...$n in to use them, i.e. to construct one can use the result of the already matched pattern. ** The restriction: When constructing we cannot use these backreferences. Neither the one from nor from and preceeding . And we also cannot use backreferences in to access the results from any successful . Two big restrictions although the information is still there. Just no way to access it in the past. Now the new functionality: 1. One can use $1..$n in any to backreference the result of . 2. One can use %1..%n in any _AND_ in to backreference the result from the last matching . (initially this is empty for ). What is the benefit? A lot of rewriting rules can be shortend and a lot of other are now the first time possible!! Example: ------- Assume we want to generate (e.g. via WML) alternative variants of HTML pages. We do this by inserting a style tag before the extension, e.g. index.html is the HTML page with the standard style while index.min.html is the one generated for Lynx users. This approach is done for a complete hierarchy of webpages. Now we want to be able to provide these variants to the user in a nice way. The nicest way is just to be able to insert the style tag at any point in the URLs of this webarea to switch the variant. For instance /our/area/ should give the index.html while /our/min/area/ or /min/our/area/ should give the index.min.html. Same for style variants like "min", "std" and "max", etc. BUT: When there is no xx.