Reverted your fixes, because they cause problems with certain CGI scripts scenarios (e.g. if the CGI script is named a valid fossil command prefix).

Instead, check for '-nocgi' option and disable automatic 'cgi' if it is present.