It is well known that the U(1) gauge vector field, with the standard five-dimensional (5D) action, cannot be localized on Randall-Sundrum-like braneworlds with an infinite extra dimension. In this paper, we propose a modified 5D action to localize U(1) gauge vector field on flat branes with an infinite or finite extra dimension. The localization method is realized by adding a dynamical mass term into the standard 5D action of the vector field, which is proportional to the 5D scalar curvature. It is shown that the vector zero mode is localizable if the 5D spacetime is (asymptotic) \(AdS_{5}\). Moreover, the massive tachyonic modes can be excluded.