How to properly set the rewrite rules for this case?

How to properly set the rewrite rules for this case?