In all prosecutions for rape and assault with intent to ravish, the court may, in its discretion, exclude from the courtroom all persons, except such as may be necessary in the conduct of the trial; and, in all other cases where the evidence is vulgar, obscene or relates to the improper acts of the sexes and tends to debauch the morals of the young, the presiding judge shall have the right, by and with the consent and agreement of the defendant, in his discretion and on his own motion, or on the motion of the plaintiffs or defendants or their attorneys, to hear and try the said case after clearing the courtroom of all or any portion of the audience whose presence is not necessary.
Ala. Code § 12-21-202 (1975)