I'm going to jump in here and make a comlete ass of myself. Usually, I have a good feel for these things, and in this case I seem to have none at all. But that won't stop me! As I say, here's where I make an ass of myself.
I think, the way they are used, 'If only I had known' and 'If I had only known' mean exactly the same thing and are interchangeable. I also believe they're idiomatic. If you look for a literal meaning of 'If only I had known,' it means if you and only you had known something; it excludes all other people from that knowledge. Yet, that isn't the way it's used or what it means. The 'only' in that usage is for emphasis, and so the usase is idiomatic, meaning the phrase has developed meaning over time that is different from the literal meaning of the words in the phrase.
That makes perfect sense to me, but might be entirely wrong.
Of the two usages, 'If only I had known' and 'If I had only known', either, by itself, sounds correct, and I'd have a difficult time saying I preferred one over the other. I think, if you held my feet to the fire, I'd use the first rather than the second because you're not spliting the verbs that way with the problematic 'only.'
I'm sure this doesn't help anyone at all, but I don't always have such a great vehicle to show my ignorance.
C