We consider the periodic solutions of a semilinear variable coefficient wave equation arising from the forced vibrations of a nonhomogeneous string and the propagation of seismic waves in nonisotropic media. The variable coefficient characterizes the inhomogeneity of media and its presence usually leads to the destruction of the compactness of the inverse of linear wave operator with periodic-Dirichlet boundary conditions on its range. In the pioneering work of Barbu and Pavel (1997), it gives the existence and regularity of periodic solution for Lipschitz, nonresonant and monotone nonlinearity under the assumption $eta_u>0$ (see Sect. 2 for its definition) on the coefficient $u(x)$ and leaves the case $eta_u=0$ as an open problem. In this paper, by developing the invariant subspace method and using the complete reduction technique and Leray-Schauder theory, we obtain the existence of periodic solutions for such a problem when the nonlinear term satisfies the asymptotic nonresonance conditions. Our result not only does not need any requirements on the coefficient except for the natural positivity assumption (i.e., $u(x)>0$), but also does not need the monotonicity assumption on the nonlinearity. In particular, when the nonlinear term is an odd function and satisfies the global nonresonance conditions, there is only one (trivial) solution to this problem on the invariant subspace.