"Rather" is an adverb, whereas "prefer" is a verb. They can never trade places because a verb cannot behave as an adverb, and vice versa. So you can say
"I would rather VERB#1 than VERB#2", or you can say
"I prefer NOUN#1 to NOUN#2".
For example: "I would rather swim than run" or "I prefer swimming to running".
Note that "swimming" and "running", being gerunds, behave as nouns.
The meaning of the two sentences is the same though, just expressed differently.