Efficient production of hydrogen via water electrolysis is one of the promising approaches to enable a complete fossil-free energy transition. Hydrogen can be utilized alongside renewable energy sources like wind and solar to smooth out their power production. It can also serve as a standalone solution to stabilize electrical grids and support various industrial processes. The most promising electrolyzer to be used for grid applications and alongside renewable energy sources is a proton exchange membrane electrolyzer, due to its fast dynamics. Due to their high cost and relatively short lifetime, they are not widely used in electric grids or industry today. With particularly designed electrodes, the proton exchange membrane electrolyzers can operate under cyclic polarity switching, which makes the electrodes self-regenerate. This increases the lifetime of the proton exchange membrane electrolyzers, as well as minimizes their efficiency drop over time. In order for polarity switching to be implemented on an industrial level, a novel solution to ensure that the hydrogen always goes to the right storage unit and is kept ultra-pure is of great importance. This paper presents an innovative modular gas routing system that enables safe polarity switching and prevents cross-contamination of gases through automatic valve control and a self-cleaning mechanism. The system was also implemented in a proof-of-concept prototype.