A person imprisoned or otherwise restrained of liberty under any pretense whatsoever, except in the cases specified in AS 12.75.020, may prosecute a writ of habeas corpus to inquire into the cause of the imprisonment or restraint, and, if illegal, to be released from custody or to be granted another remedy as law and justice require. Procedure may be as prescribed in the Rules of Civil Procedure.