improve restricted URL handling (cherry picked from commit 317e665)