We use a line of miniature Hall sensors to study the influence of the magnetic domain distribution on the flux dynamics in superconductor/ferromagnet bilayers. Two bilayers are built of a ferromagnetic Co/Pt multilayer with perpendicular magnetic anisotropy and a superconducting Nb layer, with the insulating layer in between to avoid proximity effect. The magnetic domain patterns of various geometries are reversibly predefined in the Co/Pt multilayers using the appropriate magnetization procedure. The Pt thickness is different in the two bilayers, resulting in different width and length of the domains, what profoundly affects vortex dynamics. We show that narrow, short domains lead to strong confinement of vortices at the sample edge, while narrow elongated domains of uniform width induce smaller confinement and easy vortex entry. Large enhancement of flux pinning and critical current density, by a factor of more than 7, is observed in the last case, while the former results in smaller enhancement. When domains are wide, the disorder in the domain widths becomes beneficial for larger enhancement of pinning, while more uniform distribution of domain widths results in a precipitous drop of the enhancement. The analysis of these results suggests that with increasing domain width a transition occurs from vortex chains pinned by narrow domains, to disordered triangular vortex lattice, pinned by a maze of multiply interconnected magnetic domains.