[Resource] Improved redirect to referer

Rebased version of #1296.