Try using RedirectMatch and include the "end of line" $ in the regular expression.
RedirectMatch permanent /A$ http://www.domain.com/A/B RedirectMatch permanent /A/$ http://www.domain.com/A/B
EDIT: The matches below may work a little better (in general)
RedirectMatch permanent .*/A$ http://www.domain.com/A/B RedirectMatch permanent .*/A/$ http://www.domain.com/A/B
source share