How does one say a blessing on a rainbow if one is not meant to look at a rainbow?
The nephew of Rosh (Sefer Chasidim p. 14b) asked his uncle this question. His uncle, the Rosh, replies that there is a difference between gazing (histaklus) and seeing (re’iyah). Although it is prohibited to gaze at a rainbow (see Chagigah 16a), it is permitted to look at it, for the purpose of reciting the blessing. This approach is cited in Beis Yosef (Orach Chaim 229, citing from Abudraham, in the name of Rosh).
Sources: See also Zera Emes 3:43. It is interesting to note the discussion among authorities concerning gazing at the moon, which is derived from the prohibition of gazing at a rainbow. See Orach Chaim 426:2, and Magen Avraham, Mishnah Berurah, Eliyah Rabbah, and others.