How do redirect user back to previous page when on certain pages?

How do redirect user back to previous page when on certain pages?