This paper characterizes optimal keyword auction mechanism, obtains Revenue Equivalence Theorem for keyword auctions and designs a kind of optimal keyword auction mechanism by considering the variable costs of advertisement positions. Under assumptions that the valuation of advertisement position to the advertiser is independently identically distributed, that the click-through rate depends only on advertisement positions and per-click variable costs are non-decreasing, we obtain the explicit expressions for the allocation rules and payment rules of a optimal mechanism, which is a generalization of traditional VCG mechanism.