Web sites invest significant resources in trying to influence their visibility in online search results. We study the economic incentives of Web sites to invest in this process known as search engine optimization. We focus on methods that improve sites' ranking among the search results without affecting their quality. We find that the process is equivalent to an all-pay auction with noise and headstarts. Our results show that in equilibrium, under certain conditions, some positive level of search engine optimization improves the search engine's ranking and thus the satisfaction of its visitors. In particular, if the quality of sites coincides with their valuation for visitors then search engine optimization serves as a mechanism that improves the ranking by correcting measurement errors. While this benefits consumers and search engines, sites participating in search engine optimization could be worse off unless their valuation for traffic is very high. We also investigate how search engine optimization affects sites' investment in content and find that it can lead to underinvestment as a result of wasteful spending on search engine optimization.