Custom post type single page returning 404 error when sharing archive url with custom taxonomy

So after some more research I came across this
https://stackoverflow.com/questions/23698827/custom-permalink-structure-custom-post-type-custom-taxonomy-post-name
– which I now think I remember using at some point but must have deleted thinking it hadn’t worked (as I hadn’t figured out the rest of the process). But this is the particular function and filter that worked:

/**
 * Tell WordPress how to interpret our project URL structure
 *
 * @param array $rules Existing rewrite rules
 * @return array
 */
function so23698827_add_rewrite_rules( $rules ) {
  $new = array();
  $new['news-media/([^/]+)/(.+)/?$'] = 'index.php?newsmedia=$matches[2]';
  $new['news-media/(.+)/?$'] = 'index.php?news-media=$matches[1]';

  return array_merge( $new, $rules ); // Ensure our rules come first
}
add_filter( 'rewrite_rules_array', 'so23698827_add_rewrite_rules' );