So if you want to do this programmatically then you need to retrieve the parts of the path. To do that, use the command [ getfield [HTTP::path] "/" <field number> ] getfield HTTP::path. You can also use the tcl split command to split the path into a list and check the list contents with lindex
Seems pretty simple - the pseudocode would be:
if field 2 == "sites"
if field 3 != ""
then Host = field 3.blahblah.com
endif
if field 4 != ""
then new URI = /field3
endif
redirect to $Host$URI
else
redirect to other page
endif
Hopefully you can work it out from this