If you use the TARGETURI datastore option, you can use target_uri (provided by Msf::Exploit::Remote::HttpClient), instead of datastore['URI'] here.