A significant improvement of the resistive wall mode (RWM) feedback stabilization is achieved by optimizing the poloidal locations and the linear combination of an array of sensors, detecting the radial magnetic flux. The optimization is based on the full knowledge of the dynamic response of both unstable and stable RWMs. The optimal solution is robust against the variation of plasma parameters.