  Context. Apertif is a multi-beam receiver system for the Westerbork Synthesis Radio Telescope that operates at 1.1-1.5 GHz, which overlaps with various radio services, resulting in contamination of astronomical signals with radio-frequency interference (RFI). Aims. We analyze approaches to mitigate Apertif interference and design an automated detection procedure for its imaging mode. Using this approach, we present long-term RFI detection results of over 300 Apertif observations. Methods. Our approach is based on the AOFlagger detection approach. We introduce several new features, including ways to deal with ranges of invalid data (e.g. caused by shadowing) in both the SumThreshold and scale-invariant rank operator steps; pre-calibration bandpass calibration; auto-correlation flagging; and HI flagging avoidance. These methods are implemented in a new framework that uses the Lua language for scripting, which is new in AOFlagger version 3. Results. Our approach removes RFI fully automatically, and is robust and effective enough for further calibration and (continuum) imaging of these data. Analysis of 304 observations show an average of 11.1% of lost data due to RFI with a large spread. We observe 14.6% RFI in auto-correlations. Computationally, AOFlagger achieves a throughput of 370 MB/s on a single computing node. Compared to published machine learning results, the method is one to two orders of magnitude faster. 
An interference detection strategy for Apertif based on AOFlagger 3