You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Riggs <ap...@riggs.me> on 2014/05/05 22:14:16 UTC

[patch] regexp rewrite map

[Posting separately to both dev and users to see if anyone on either side sees value in getting this committed.]

About a year ago, I had an idea for a new type of RewriteMap that would fill an important need for a few particular use cases that we have [1]. While we were at ApacheCon in Denver, I spent some time talking with JimJag, Rich, and Covener as well as updating the code from a crude proof of concept to something real. I would appreciate feedback from anyone, especially on whether or not this is something worth pursuing getting committed.

It is a simple concept: the map is just a list of regexp patterns and replacements. These could be done as individual RewriteRules, obviously, but this rewrite map would reduce clutter in the config file, be more readable, and could even be externally generated/maintained without any httpd admin involvement. For example, an application or batch job could generate a map file with dozens or hundreds of entries that httpd would pick up without a restart/graceful, and the config might only contain a single RewriteRule:


[map file]
/foo(bar)?             /baz$1
/(apple|banana|orange) /fruit/$1
/post/(\d+)(/.*)?      /article/$1$2
...


[config file]
RewriteMap "regexptest" "regexp:path/to/re.map"

RewriteCond "${regexptest:$1}" "^(.+)$"
RewriteRule "^(.*)$" "%1" [R]
...


Possible use cases that I can think of:

1. Redirect list (e.g. legacy site to new site) without pages of RewriteRules/Redirects
2. Simplify 100s or 1000s of rewrite rules into 1 + the map as above
3. "White list" of URL patterns to proxy through to backend servers (can be application generated; my particular use case)
4. Maps could be application generated, maintained in a spreadsheet or DB, or created with scripts/greps/etc.

Just like text and hash maps, results are cached. I did some tests with up to 100K entries in the map, and it was still extremely responsive and worked flawlessly. The only thing this doesn't have is flags (e.g. NC), but that can be handled in the pattern itself via (?i).

If interested, I would love it if some folks would try the attached patch and let me know what you think.

- Jim

[1] http://httpd.markmail.org/thread/3dheejtgwmdpxxt5


Re: [patch] regexp rewrite map

Posted by Rich Bowen <rb...@rcbowen.com>.
This seems like a cool idea. While I have no use for the functionality
myself I encounter people on irc every day that could benefit from
something like this to simplify complex rewrite sets.

-- 
Rich Bowen, mobile edition
rbowen@rcbowen.com
On May 5, 2014 4:14 PM, "Jim Riggs" <ap...@riggs.me> wrote:

> [Posting separately to both dev and users to see if anyone on either side
> sees value in getting this committed.]
>
> About a year ago, I had an idea for a new type of RewriteMap that would
> fill an important need for a few particular use cases that we have [1].
> While we were at ApacheCon in Denver, I spent some time talking with
> JimJag, Rich, and Covener as well as updating the code from a crude proof
> of concept to something real. I would appreciate feedback from anyone,
> especially on whether or not this is something worth pursuing getting
> committed.
>
> It is a simple concept: the map is just a list of regexp patterns and
> replacements. These could be done as individual RewriteRules, obviously,
> but this rewrite map would reduce clutter in the config file, be more
> readable, and could even be externally generated/maintained without any
> httpd admin involvement. For example, an application or batch job could
> generate a map file with dozens or hundreds of entries that httpd would
> pick up without a restart/graceful, and the config might only contain a
> single RewriteRule:
>
>
> [map file]
> /foo(bar)?             /baz$1
> /(apple|banana|orange) /fruit/$1
> /post/(\d+)(/.*)?      /article/$1$2
> ...
>
>
> [config file]
> RewriteMap "regexptest" "regexp:path/to/re.map"
>
> RewriteCond "${regexptest:$1}" "^(.+)$"
> RewriteRule "^(.*)$" "%1" [R]
> ...
>
>
> Possible use cases that I can think of:
>
> 1. Redirect list (e.g. legacy site to new site) without pages of
> RewriteRules/Redirects
> 2. Simplify 100s or 1000s of rewrite rules into 1 + the map as above
> 3. "White list" of URL patterns to proxy through to backend servers (can
> be application generated; my particular use case)
> 4. Maps could be application generated, maintained in a spreadsheet or DB,
> or created with scripts/greps/etc.
>
> Just like text and hash maps, results are cached. I did some tests with up
> to 100K entries in the map, and it was still extremely responsive and
> worked flawlessly. The only thing this doesn't have is flags (e.g. NC), but
> that can be handled in the pattern itself via (?i).
>
> If interested, I would love it if some folks would try the attached patch
> and let me know what you think.
>
> - Jim
>
> [1] http://httpd.markmail.org/thread/3dheejtgwmdpxxt5
>
>
>
>
>
>