This is not done by the router it is done by the web server itself. You must use a single machine to host both sites...it is technically possible to use multiple but the first machine must still take the traffic.
To make this work you must have multiple domains registered to the same address. so if I have site1.com and site2.com both registered to 220.127.116.11. The traffic will come to 18.104.22.168 and be port forwarded to your server say 192.168.0.10. Now inside the actually HTTP headers you will actually see the site1.com or site2.com data strings that the user passes. Most web servers already know how to do this you just need to configure it to work it is not something you have to code yourself. Follow the instructions in the previous post.
This is why some sites you can open the url by name but you get errors if you key in the IP address directly.