I've been caught in rip currents tons of times. I always swim sideways TOWARDS THE SHORE. this survival tip can help you understand what you need to do.
The resistance of the rip enables you to turn out of the current faster. If you swim sideways with the current the current gets wider the farther you go out. So you wind up doing A LOT more swimming. My advice is swim towards the current horizontally. The closer you are to shore the more narrow the current is. So you just swim hard as fuck for 5-10 minutes, then you don't have to swim half a mile back to shore.