We present theoretical and experimental results on switching and tuning of a two-dimensional photonic crystal resonant microcavity by means of a silicon AFM tip, probing the highly localized optical field in the vicinity of the cavity. On-off switching and modulation of the transmission signal in the kHz range is achieved by bringing an AFM tip onto the center of the microcavity, inducing a damping effect on the transmission resonance. Tuning of the resonant wavelength in the order of several nanometers becomes possible by inserting the AFM tip into one of the holes of the Bragg mirror forming the microcavity in the propagation direction. (c) 2006 Optical Society of America.