I'm afraid there aren't rules, because the formatin is rather idiomatic. You have to learn them each in their own context.
I was born in 1966. I was born in May. I was born on the 23rd. I was born at 11:41 at night: In for year and month, on for date, at for time... you can see it's variable.
"For weeks" means a duration of a few weeks. "In a few weeks" means at the end of a few weeks.
"I'll be away for a while" means for some undetermined period, I will be gone. "I'll go away in a while" means after some undetermined period, I will leave.
Looking for ESL work?: Try our EFL / TOEFL / ESL Jobs Section!
For example, you can reverse the prepositions in your two examples with no change in meaning. (I haven't seen her for a while. I haven't seen her in weeks.) Both are commonly used.
In other examples there might be a slight change in meaning. In still others, the switch would not be allowed, although logically you'd say it should. My feelings are the same as yours. My feelings are similar to yours. My feelings are the same to yours. My feelings are similar as yours. (The last pair would not be allowed.)
I think you just have to learn the applicatations one by one. Perhaps someone on the team can give you better advice.
Edit. (just saw GG's post) If you swap in and for in her last two examples, "I'll go away for a while" is a very common expression with a new meaning. "I'll be away in a while" is logically possible, but unheard of.
I heard a phrase like "I haven't seen her in years". I guess I could say "I haven't seen her for years" with no change in meaning at all. Am I right?Yes, that's right.
It seems to me that for is the general purpose preposition for this situation.
In contrast in seems to be associated with non-assertive contexts, and (slightly) preferred there.
So I've done that for years is possible but *I've done that in years is not.
I haven't done that for years and I haven't done that in years are both fine.
You might say I've struggled with this problem for months, but not *I've stuggled with this problem in months.
Sentences like It's the only one I've seen in years are fine. It is not an assertion of 'seeing it for years'. It's non-assertive.