Topics: User Forum
Dec 7, 2010 at 5:44 PM
Edited Dec 7, 2010 at 6:15 PM

Hi guys!
I have the following table of groups/subgroups, witch translate "Group" and "subGroup" to their "codes":
GroupA = 1
GroupA / SubGroupX = 1
GroupA / SubGroupY = 2
GroupA / SubGroupZ = 3
GroupB = 2
GroupB / SubGroupX = 3
GroupB / SubGroupY = 2
GroupB / SubGroupZ = 1
and I want to accept and translate urls like those:
mysite/A -> mysite/myurl?group=1
mysite/A/X -> mysite/myurl?group=1&subgroup=1
mysite/B/X -> mysite/myurl?group=2&subgroup=3

I've learned how to translate "A" to "group=1" using a mapping file "Group" that contains "A 1, B 2 etc" and a rule wrote like this:
RedirectRule ^/(.*)$ /myurl?group=${Group:$1}

But... how to add the second value, witch is depending on value of first?
That is, I cannot create a mapping file containing the following:
X 1
Y 2
Z 3
because it would be correct only for A, and not for B.
Shoud I create as many subgroup mappings files as groups I have? If so, how to use them?

Any help/hint would be appreciated!

Dec 14, 2010 at 1:34 PM

There's no concise way to do this.  You must map every pair, every combination.  you can do it with one large map, or with nested maps.

What I would try if I were you:  use the combination of AX, BX, AY, BY, etc, as the key to lookup into one large map.  Something like this:

RewriteMap  bigmap  txt:c:\maps\ubermap.txt
RewriteRule  ^/mysite/([^/]+)(/([^/]+))?$ /mysite/${bigmap:$1$3} [L]

What this does:  It matches on incoming URLs like /mysite/A/X as well as /mysite/A . The second capture group in the regex is followed by a ?, which means "zero or 1 of the previous".  Therefore this second group captures /X if it is present, or nothing if it is not present.  The inner capture group is the 3rd, and it captures just the X (without the slash), or nothing.  In this rule, $1$3 is the key used to lookup into bigmap.  In this example, $1$3 will be either A or AX.  Therefore in your map file you need entries for both of those, as well as for B BX BY and so on. The result of those lookups might be, in your case, for AX


...and so on.

You can also do this via nested maps, but that can be more complicated.

good luck.