We propose a scheme for a deterministic controlled-phase gate between two photons based on the strong interaction between two stationary collective Rydberg excitations in an atomic ensemble. The distance-dependent character of the interaction causes both a momentum displacement of the collective excitations and unwanted entanglement between them. We show that these effects can be overcome by swapping the collective excitations in space and by optimizing the geometry, resulting in a photon-photon gate with high fidelity and efficiency.Deterministic quantum gates between individual photons are very desirable for photonic quantum information processing [1][2][3][4][5]. As photons interact only very weakly in free space, the implementation of such gates requires appropriate media. One attractive approach involves converting the photons into atomic excitations in highly excited Rydberg states, which exhibit strong interactions. Rydberg state based quantum gates between individual atoms and between atomic ensembles have been proposed [6][7][8][9][10] and implemented [11][12][13]. There are two categories of gates, those relying on the interaction between two excited atoms [6,7], and those based on Rydberg blockade [7][8][9][10][11][12][13], where only one atom is excited at any given time. There is a significant body of work studying the effects of mapping photons onto collective atomic Rydberg excitations [14][15][16][17][18][19][20]. Most proposals for photon-photon gates involve propagating Rydberg excitations (polaritons), either using blockade [21,22] or two excitations [23][24][25][26].Separating the interaction process and propagation makes it easier to achieve high fidelities for these photonic gates [27]. Such separation can be achieved by photon storage, i.e. by converting the photons into stationary rather than moving atomic excitations. The only storagebased photonic gate that has been proposed so far is based on the blockade effect [27]. Achieving blockade conditions can be challenging since both photons have to be localized within the blockade volume. Following [6,7,[23][24][25][26], we here propose a storage-based scheme that instead relies on the interaction between two stationary Rydberg excitations.The main challenge for two-excitation based Rydberg gates in atomic ensembles arises from the fact that the interaction is strongly distance-dependent and thus not uniform over the profiles of the two stored photons. We show that this a priori reduces the gate's fidelity by displacing the collective excitations in momentum space and by entangling their quantum states. However, we then show that it is possible to completely compensate the first effect by swapping the collective excitations in the middle of the interaction time, and to greatly alleviate the second effect by optimizing the shape and separation of the excitations, resulting in a photon-photon gate that achieves both high fidelity and high efficiency. Now we describe our scheme in detail. As shown in Fig. 1a, information is encoded in dual-rail...