New metal-organic frameworks (MOFs) based on zinc and cadmium ions, terephthalic acid, and flexible ligands 1,5-bis(imidazol-1-yl)pentane or 1,6-bis(imidazol-1-yl)hexane were prepared and characterized by X-ray diffraction, thermorgavimetric analysis and IR spectroscopy. The imidazolyl ligands were prepared by a new robust procedure involving the reaction between imidazole and 1,5-dibromopentane or 1,6-dibromohexane in a superbasic medium (KOH in DMSO). MOFs based on 1,5-bis(imidazol-1-yl)pentane had diamond topology (dia) and are triply interpenetrated. Ligands with longer spacer 1,6-bis(imidazol-1-yl)hexane, terephthalate ions and zinc(II) ions formed five-fold interpenetrated metal-organic framework also with dia topology, while cadmium(II) ions with the same ligands formed eight-connected uninodal net with a very rare self-penetrated topological type ilc and a point symbol 424 .5.63. The influence of the chemical composition of MOFs on their photoluminescent properties is investigated and discussed in detail.