From your description, you are trying to define a RewriteMap in context for each directory through your .htaccess file, but this is not valid. RewriteMap can only be defined in the context for each server, either in the configuration of the primary server or in the virtual server section.
When you make requests to the server, and the .htaccess file .htaccess parsed, it encounters the RewriteMap directive and gives a warning, which causes an error 500. Probably, you will see an entry in your error_log saying that "RewriteMap is not allowed here."
source share