Spiekerooger - 2:03 pm on Sep 19, 2010 (gmt 0)
this is a tough one.
Two problems: mod_rewrite doesn't even get the part after the #anchor, therefor query-string is empty. It's also not covered by THE_REQUEST - Apache simply doesn't care for anchors, it's only important for the html file accessed.
The url is acutally malformed, it should be ?foo=bar#anchor :/
But there's something positive as well: search engines do not care for anchors either, so you won't get a dc issue here. The query string is just seen as part of the anchor, not the url.
Edit: my testing and typing was too slow. ;) phranque already answered the technical part.