Re: RewriteMap and RewriteRule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2008/12/6 Krist van Besien <krist.vanbesien@xxxxxxxxx>:
> On Sat, Dec 6, 2008 at 3:05 AM, Clodoaldo Pinto Neto
> <clodoaldo.pinto@xxxxxxxxx> 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?

Exactly

> 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]

Almost that. It worked like this:

      RewriteMap redirect txt:/var/www/html/example/redirect.txt
      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.

This explanation was what i needed. Without it  i would spend the
whole weekend trying.

Thanks, Clodoaldo

>
> Krist
>
> --
> krist.vanbesien@xxxxxxxxx
> krist@xxxxxxxxxxxxx
> 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 <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
>   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
> For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux