Return-Path: Delivered-To: apmail-httpd-users-archive@www.apache.org Received: (qmail 16192 invoked from network); 6 Dec 2008 16:16:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Dec 2008 16:16:26 -0000 Received: (qmail 52366 invoked by uid 500); 6 Dec 2008 16:16:28 -0000 Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 52353 invoked by uid 500); 6 Dec 2008 16:16:28 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 52342 invoked by uid 99); 6 Dec 2008 16:16:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Dec 2008 08:16:28 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of krist.vanbesien@gmail.com designates 72.14.220.156 as permitted sender) Received: from [72.14.220.156] (HELO fg-out-1718.google.com) (72.14.220.156) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Dec 2008 16:14:59 +0000 Received: by fg-out-1718.google.com with SMTP id 16so346372fgg.40 for ; Sat, 06 Dec 2008 08:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=0jG5OtDN0ZJvllhvPV7SmApVGb9c9V8VvaoHzLHYS8U=; b=hxSsJh5k3r4jSI0ICamQxV8+ar0SBep0dqnvDyT/WgyT/jbMfov+zPpqkmJ8y+Cxqg lJkyYaFk9kvbQE1YCupFdLLDkZ+9fdVVRgkRiVzG154o70LeF6LHA0pJnX5KKzEALuy8 slMiM+AqIsfh+F74kdLUG8NMiViQAp6Msl90U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=cDxlBqx+QS660pgI7i4KUAJzjDNFo7IIheoBVgGSo1tD/GIu27Lwoa0v2seNaVS1BN OoYJsjFpY7YV/9XwUa7J4WwhI3JGmxVVehyncud8AKYyZRD3AkqCrZzVo/8NSMuQMlif 5uUS5IWeRmUHXAA5gv5mpNMN+9fwoQAQcggXY= Received: by 10.86.100.19 with SMTP id x19mr1446778fgb.29.1228580137137; Sat, 06 Dec 2008 08:15:37 -0800 (PST) Received: by 10.86.2.17 with HTTP; Sat, 6 Dec 2008 08:15:37 -0800 (PST) Message-ID: <6ed6382b0812060815q35f38723m5c9550a6ed76ab80@mail.gmail.com> Date: Sat, 6 Dec 2008 17:15:37 +0100 From: "Krist van Besien" To: users@httpd.apache.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org Subject: Re: [users@httpd] RewriteMap and RewriteRule On Sat, Dec 6, 2008 at 3:05 AM, Clodoaldo Pinto Neto wrote: > I'm using this config in Apache 2.2.3/Centos 5: > > RewriteMap redirect txt:/var/www/html/example/redirect.txt > > RewriteRule ^/(a|b|c|d|e)$ http://example.com/${redirect:$1} [NC,R=permanent,L] > > redirect.txt: > a x > b y > c z > d k > e j > > Since the redirected pages are many i would like to not have to put > them all in RewriteRule ^(a|b|c|d|e)$ using in instead the > redirect.txt map to populate that rewrite rule. Is it possible? If not > what else can be done? Basically you want the rule not to change the URL if there is no macht in redirect.txt, right? I had a similar need a while ago. I can't look at the exact solution I implemented then (as I'm not in the office at the moment) but it was something like this: RewriteCond ${redirect:$1} (^.+$) RewriteRule (.*) http://example.com/%1 [NC,R=permanent,L] This gets processed in the following order: - (.*) is matched against the URL. URL is captured in $1 - $1 gets looked up in the redirect map. The result gets matched against an non empty line (that's what ^.+$ is) and if there is a match, it getst captured in %1, and the RewriteRule can proceed. - The rule gets rewriten to http://example.com/%1 (%1 is what we captured in the RewriteCond). The advantage of this construct is that if URL isn't found in your rewritemap than the whole RewriteRule fails, and rule processing continues, which makes it possible to have other rules for the cases you can't solve with your rewritemap. A last note: If your redirect map gets large use dbm maps, not text maps. They are a lot faster. Krist -- krist.vanbesien@gmail.com krist@vanbesien.org Bremgarten b. Bern, Switzerland -- A: It reverses the normal flow of conversation. Q: What's wrong with top-posting? A: Top-posting. Q: What's the biggest scourge on plain text email discussions? --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See for more info. To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org " from the digest: users-digest-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org