[ticket/12358] Correctly check and change the redirect url for ajax requests

PHPBB3-12358