Due to refraction, the oceanic ridge acts as a waveguide forcing long-period waves to propagate along the topography. Based on the linear shallow water equations, analytical solutions of trapped waves over a hyperbolic-cosine squared ocean ridge are obtained, which are described by combining the associated Legendre functions of the first and second kinds. The spatial distribution pattern for each mode is discussed, and the wave amplitude gets the maximum at the ridge top and decays gradually towards both sides. The higher the mode number, the slower the rate of amplitude decreases, so that more energy is distributed over more of the ridge. The trapped wave number is not only related to the frequency, but also to the varying water depth parameters.