Custom post type single with custom URL structure

The code you are using looks valid, so…

Before going any further, check to see that the post you are testing with actually has the term you are expecting to find (and replace). In other words, verify your input is valid.

Also, you might consider just doing a straight string replace on the URL as, if the search term doesn’t exist, no harm will be done. That said, if the search term does exist in the post name, for example, it will have unintended consequences so, you might also consider making the search more specific (like adding / (slash) to the search term).

Assuming the input is valid, you might also consider making this change in your rewrite rules (in apache or nginx) rather than in PHP. The reason is if you ever move to a new theme, for example, the functionality won’t change (and it might even be faster than processing every request in PHP).