There are $P\in U(n),Q\in U(p)$ s.t.  $A=P^*\Delta P,Q^*BQ=D$ where $\Delta,D$ are diagonal real; then

$Q^*X^*P^*\Delta PXQ=D$, that is 

$(1)$ $U^*\Delta U=D$, where $PXQ=U=[u_{i,j}]\in M_{n,p}$ or $X=P^{-1}UQ^{-1}$.

Equation $(1)$ is a system of $p(p+1)$ equations  in the $2np$ real unknowns $Re(u_{i,j}),Im(u_{i,j})$.

 We assume that $rank(B)=p$. If $rank(A)<p$, then, clearly, there are no solutions; assume that $n\geq rank(A)\geq p$

$\textbf{Proposition}$. Let $signature(\Delta)=(k+,l-),signature(D)=(r+,(p-r)-)$. If $k\geq r,l\geq p-r$, then there are many solutions in $U$ that depend at least on $p^2$ real parameters. When $rank(A)=p$, the solutions depend at least on $2np-p^2$ parameters;

$\textbf{Proof}$.  We may assume that $\Delta=diag(\epsilon_{n-p},\delta_p)$, where $signature(\delta)=signature(D)$ and $U=\begin{pmatrix}V\\W_p\end{pmatrix}$; we impose $V=0$. Then $(1)$ can be written 

$(2)$ $W^*\delta W=D$ where all the matrices are $p\times p$ and invertible.

$(2)$ is a system of $2p(p-1)/2+p=p^2$ equations in $2p^2$ real unknowns and moreover, $(2)$ admits real solutions $W$ (if $\Delta$ and $D$ have distinct eigenvalues, then $W$ is associated to a permutation of the elements of the basis, then to homotheties). We deduce the first result.

Now, if $rank(A)=p$, then $\epsilon=0$ and $V$ is arbitrary. We obtain at least $2p(n-p)+p^2=2np-p^2$ parameters.  $\square$