We present a terahertz gas sensor based on a simple one-dimensional photonic crystal cavity. Although the manufacture process is quite easy, this cavity exhibits quite high quality factors for assisting the realization of very high sensitivity in the gas refractive index sensing. Transmission measurements of the one dimensional photonic crystal cavity under different gaseous environments showed that the resonant frequency depends linearly on the refractive index of the ambient gas. In our experiment, a change of the refractive index by 1.4×10<sup>-5</sup> leads to a shift of the resonant frequency by 4 MHz, which corresponds to 6% of the change of hydrogen concentration in air. By using the former reported quality factor of ~1.1×10<sup>4</sup>, a refractive index change as small as 7×10<sup>-6</sup> can be expected.
A terahertz one-dimensional photonic crystal (PC) cavity with high Q-factor is demonstrated theoretically and experimentally. The cavity consists of two parallel distributed Bragg mirrors and one air layer between them as defect layer. By increasing the length of the defect layer, the cavity has a very narrow transmission bandwidth (FWHM) of 30MHz at resonant frequency of 336GHz, i.e. a high Q over 1.1×10<sup>4</sup> is achieved. What's more, an optically controllable THz switch is demonstrated by light irradiating on one of the middle silicon wafer in the cavity, the optical beam power needed for the switch is remarkably reduced to 0.16 W/cm<sup>2</sup>, which is nearly 50 times smaller than that for a THz switch using a single silicon wafer. Finally, such high Q cavity is very sensitive to the refractive index change in the cavity, it is suitable to be used in gas sensing. The experimental results verified its applications in H<sub>2</sub>, N<sub>2</sub>, and CO<sub>2</sub> gas detections.