plugin development – rewrite URL based on selected taxonomy for post page

I have a taxonomy called “group”, and their values like “red”, “blue”, “green” (these are generating dynamic” no any fixed group value.

during post publish I am selecting “Group” for each post. 1 group for each post.

I want to add a rewrite URL for the post if the taxonomy is “red” or “blue” or “green” then the URL of that post should come like

"" or "" or ""

add_action( 'init', 'create_group_tax' );
function create_group_tax() {
             array( 'label' => 'Group', 
                    'hierarchical' => true


also, I want to make it regex rule “'^red/((^/)*)/?'” dynamic with selected taxonomy,this time just to make a test i added it as a static string.

result : Page not found. Nothing here – http://localhost/wordpress/red/my-test/

what do you suggest to do this?