If you use TARGETURI you could use the target_uri method from Msf::Exploit::Remote::HttpClient. Also you could benefit from the normalize_uri function to build URL's.