I've been a TA for UNIX Administration course here at Faculty of Mathematics and Physics, Charles University in Prague. We give something similar to our students as an assignment. :-) Despite my focus on BSDs I can also operate and explain iptables (even nftables at this level!), because what you need is a simple service "forward XX to IP:YY" written as NAT rules (maybe connection tracking), plus the checks if the target responds, plus all the buttons that enable and disable particular routes.
I don't mention my previous experience with PHP, because I don't think it is a good language. But if you insist, I can use it ;-) I'd prefer shell (ksh, bash). Despite checks to ensure the system doesn't enter an invalid state, the tricky bit is to handle all the ways through the system (many interfaces, rdr-to localhost is special, which is why the iptables REDIRECT target exists).
If the destination stops responding long after a route has been set up, should the solution detect that and notify you? That would require the cron script or some daemon to do some tests over time.