Solving the Pell equation via Rédei rational functions