What properties must a ring $R$ have so that for any $a, b \in R$, we have $$(a)(b)=(a) \cap (b)?$$
If $k$ is a field, then in $k[x_1, \dots, x_n]$ I believe we have $(g)(h)=(g) \cap (h)$:
We always have $(g)(h) \subset (g) \cap (h)$ and conversely, if $f \in (g) \cap (h)$, then we can write $f=ag \in (h)$, hence $f=abgh \in (gh)=(g)(h)$.
Is this correct?
This is not true in any integral domain that is not a field. Consider some $a\in R$ that is not a unit. Then $(a)^2\neq (a)\cap (a)$ because $a\notin (a)^2$. It's probably not true in general rings either, but the easy proof in integral domains relies on the cancellation property which is not present in general rings.
The problem with your proof is that even though $f=ag$ for some $a$, this does not imply that $f=abgh$. We only know that it is also the case that $f=bh$ for some $b$. There's no way to promote this to a multiple of $gh$ in general.
You commented: "If $f$ is a multiple of $g$ and $h$, then isn't it a multiple of $g\cdot h$?" This isn't even true for the integers. Take $g = 3$ and $h=6$. Then $f=6$ is a multiple of both $g$ and $h$ but not of $gh$.
To compile some comments, it would be true in a division ring (including fields), a ring with no proper nontrivial two-sided ideals, or any direct product of such rings.
In the currently only other answer it is stated that this is true if and only if $R$ is von Neumann regular. In fact the result is that the ring is strongly von Neumann regular, which means for any $a$ we have an $x$ such that $a=aax$. Ordinary von Neumann regular rings satisfy $a=axa$ for some $x$. It is clear that if the ring satisfies $(a)(b)=(a)\cap (b)$ for all $a,b$ then $R$ is strongly von Neumann regular. The opposite direction works for commutative rings, but it is unclear if it is valid for noncommutative rings.