Ofloxacin (OFL), as a typical third-generation fluoroquinolone antibiotic, has been widespread employed in applications of preventing and treating skin tissue and bacterial infections. Detection of the residual OFL in water environment is extremely urgent on account of its toxicity to human body. Herein, a photoelectrochemical (PEC) aptasensor has been developed and fabricated for OFL determination based on CoAl layered double hydroxide/graphitic carbon nitride (CoAl LDH/g-C3N4) with two-dimensional/two-dimensional (2D/2D) structure. Strongly coupled 2D/2D structure with closed-connected contact can be beneficial to the formation of large numbers of high-speed transfer channels at the interfacial heterojunction, thereby shortening the transmission distance of carriers. Photocurrent signal of 2D/2D CoAl LDH/g-C3N4 heterojunction realized the remarkable amplification, endowing it excellent PEC performance. Based on the oxidation of OFL by photoinduced holes, this developed aptasensing platform exhibited a wide linearity range of 1 × 10–2~1 × 105 pmol L–1 with a low limit detection of 3.4 fmol L–1, along with anti-inference and feasibility for OFL assay in actual water samples. This design can be proposed by the layered structure materials coupled with g-C3N4 to significantly amplify the photocurrent signal, which opens the way for the field of PEC analysis and environmental pollutants detection.