According to Dictionary.com
[dif-i-kuhlt, -kuh lt]
- not easily or readily done; requiring much labor, skill, or planning to be performed successfully; hard
a difficult job.
- hard to understand or solve
a difficult problem.
3.hard to deal with or get on with
a difficult pupil.
adjective, harder, hardest.
1.not soft; solid and firm to the touch; unyielding to pressure and impenetrable or almost impenetrable.
2.firmly formed; tight
a hard knot.
3.difficult to do or accomplish; fatiguing; troublesome
a hard task.
etc. (many more)
In what situations is there a preference over the other? What are the rules for that?
Good answers have already been given and accepted, but I’ll just add that the word “difficult” might be seen as slightly more formal and/or sophisticated than “hard” in some contexts. I would lean toward “difficult” in formal writing. “Hard” can come across as a bit rough and workmanlike, so to speak.