The presence of topography poses a challenge for seismic modeling with finite-difference codes. The representation of topography by means of an air layer or vacuum often leads to a substantial loss of numerical accuracy. A suitable modification of the finite-difference weights near the free surface can decrease that error. An existing approach requires extrapolation of interior solution values to the exterior while using the boundary condition at the free surface. However, schemes of this type occasionally become unstable and may be impossible to implement with highly irregular topography. One-dimensional extrapolation along coordinate lines results in a simple and efficient scheme. The stability of the 1D scheme is improved by ignoring the interior point nearest to the boundary during extrapolation in case its distance to the boundary is less than half a grid spacing. The generalization of the 1D scheme to more than one dimension requires a modification if the boundary intersects the finite-difference stencil on both sides of the central evaluation point and if there are not enough interior points to build the finite-difference stencil. Examples for the 2D constant-density acoustic case with a fourth-order finite-difference scheme demonstrate the method's capability. Because the 1D assumption is not valid in two dimensions if the boundary does not follow grid lines, the formal numerical accuracy is not always obtained, but the method can handle highly irregular topography.