The optimal control problem for Burgers equation was first considered by Castro, Palacios and Zuazua. They proved the existence of a solution and proposed a numerical scheme to capture an optimal solution via the method of "alternate decent direction". In this paper, we introduce a new strategy for the optimal control problem for scalar conservation laws with convex flux. We propose a new cost function and by the Lax–Oleinik explicit formula for entropy solutions, the nonlinear problem is converted to a linear problem. Exploiting this property, we prove the existence of an optimal solution and, by a backward construction, we give an algorithm to capture an optimal solution.