[1.7.x] Fixed #21795 -- Made add_preserved_filters account for url prefixes.

Thanks to trac username honyczek for the report. Refs #6903.

Backport of 4339e9a92d from master