A near-optimal midcourse trajectory shaping guidance algorithm is proposed for both air and ballistic target engagement mission attributes for generic long range interceptor missile. This guidance methodology is based on the maximum final velocity as the objective function and maximum permissible flight altitude as the in-flight state constraint as well as the head-on orientation as the terminal state constraint for anti-ballistic trajectory. Guidance algorithm utilizes the combination of the Generalized Vector Explicit Guidance or GENEX guidance with the Bezier curve-generating functions. Nominal Bezier curves are fitted by choosing control points intuitively. Waypoints are then selected on the curve to divide it to suitable portions according to the curve’s length and curvature. These waypoints are then fed into the GENEX guidance law. To avoid acceleration command jumps, an algorithm is designed to switch to the next waypoint at a distance from the current currently-approaching waypoint. To provide near-optimality and meet the in-flight and terminal constraints, all the guidance algorithm parameters including Bezier control points, waypoints, switching distances and the GENEX law gain are optimized using Genetic Algorithm by setting the mentioned cost function and constraints. Simulation results show better performance compared to nominal trajectories while ensuring the flight altitude constraint for air target and head-on orientation for ballistic target.