It needs to modified based on your server link configuration. is your ciwweb.pl reside in common cgi-bin directory or upload separately for each project? I assume you need to change path cgi-bin/ciwweb.pl here, rest seems fine in below code.
str = str.replace('index.html?name=','cgi-bin/ciwweb.pl?hid_studyname=HtmlRedirectionLive&username=');
Also can you confirm what is your studyname, SpeechHtmlLive1 or HtmlRedirectionLive.