Rewrite rules for using the same base slug for multiple content types

Ok, the solution here turned out to be setting the correct priority on the add_action hook. Since we’re all hooking into init to register our post types per the Codex, the priority will determine which register_post_type function gets called first and, by extension, the order of the generated rewrite rules.

So, I needed my “gemstone” rewrite rules to be checked before the “product” rewrite rules, so if they match, the product rules won’t even be checked. It’s a bit annoying that I had to use a negative value for the priority argument to achieve this because WooCommerce uses a priority of 0 for their register post type action, but that’s a minor issue.

I still don’t know how best to make the attachment pages work (the bonus question from above), but that is probably best left to the core WooCommerce team.