Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A change in how a site is structured means urls need changing from




i.e. I want to use a RewriteRule to subtract a constant (in this example, 10) from the integer in the 2nd argument and another constant (in this example, 20) from the integer in the 3rd argument.

These simple calculations would save literally millions of 301 redirects that would need handling. Is there any way to do it using mod_rewrite?

share|improve this question
up vote 4 down vote accepted

No, but you can use a RewriteMap and have your variables processed by an external program:

MapType: prg, MapSource: Unix filesystem path to valid regular file

Here the source is a program, not a map file. To create it you can use a language of your choice, but the result has to be an executable program (either object-code or a script with the magic cookie trick '#!/path/to/interpreter' as the first line).

This program is started once, when the Apache server is started, and then communicates with the rewriting engine via its stdin and stdout file-handles. For each map-function lookup it will receive the key to lookup as a newline-terminated string on stdin. It then has to give back the looked-up value as a newline-terminated string on stdout or the four-character string ``NULL'' if it fails (i.e., there is no corresponding value for the given key). A trivial program which will implement a 1:1 map (i.e., key == value) could be:

$| = 1;
while (<STDIN>) {
    # ...put here any transformations or lookups...
    print $_;
share|improve this answer
But take care, this will gain some delay and you can only specify RewriteMap in the context of the server config and virtual host. – DrDol Aug 14 '10 at 23:13

There is no calculation within it,

While it does have grouping (count of ocurrences) and mapping i would recommend you to use a global rediction to a main index.php and from there create the page it should be displaying by the request data (get,post,cookie,etc) which is what the big forums and most CMS do (examples are, vbulletin, wordpress, ipb) ...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.