I just got this working for a site following a couple of posts on this forum, I'm using a rewrite rule with NE not escape and R=301 redirect options:
RewriteRule ^galleries/([a-zA-Z0-9_-]+)$ /gallery.html#/$1 [R=301,NE,L]
This redirects all galleries/variable to /gallery.html#/variable
Edit: The important part of the rule is NE which instructs the server to parse output without escaping characters. Without this, it will try and escape the # in the rewrite rule which is what the OP is asking about.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…