סימן קד סעיף יא
אָסוּר לְגַלֵּחַ בְּחֹל הַמּוֹעֵד, אֲפִלּוּ גִּלַּח אֶת עַצְמוֹ גַּם בְּעֶרֶב יוֹם טוֹב, אֶלָּא מִי שֶׁיָּצָא מִבֵּית הָאֲסוּרִים. וַאֲפִלּוּ יָצָא בְּעֶרֶב יוֹם טוֹב, אֶלָּא שֶׁלֹּא הָיָה לוֹ פְּנַאי לְגַלֵּחַ אָז (וְעַיֵּן עוֹד לְקַמָּן סִימָן ר"כ סָעִיף ו) (תקנ"א).
It is forbidden to shave27To take a haircut is also forbidden. on Chol Hamoed,28Maseches Moed Katan 14b. This is a Rabbinic prohibition to make sure that you shave erev Yom Tov so you will not enter Yom Tov looking disheveled. (see Taz, Magein Avraham 531:1) even if you shaved on erev Yom Tov.29Shulchan Aruch 531:2. Because people may not know you shaved before Yom Tov and will think everyone is permitted to shave on Chol Hamoed. (Beis Yosef) But a person who has been released from jail,30This includes all situations where everyone knows you were not able to shave before Yom Tov. (see Sha’ar Hatziyun 531:7, Ritva) even if he was released erev Yom Tov, but had no time31The Mishnah Berurah 531:7 disagrees with the ruling and permits it only if he was released from jail (etc.) near nightfall when there was no time. (see Sha’ar Hatziyun 531:9) to shave then, is permitted to shave on Chol Hamoed.
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)