• Hi.

    When the url contains “@” characters, it cannot be redirected correctly via the wp_redirect function.
    The wp_redirect will make trouble when the url has an email address.

    This is because the @ is removed in the wp_sanitize_redirect function.

    Let me show you the code.

    function wp_sanitize_redirect($location) {
    	$location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location);
    	$location = wp_kses_no_null($location);
    
    	// remove %0d and %0a from location
    	$strip = array('%0d', '%0a', '%0D', '%0A');
    	$location = _deep_replace($strip, $location);
    	return $location;
    }

    I think the regular expression phrase should contain an @ character.
    This is what I am saying.

    $location = preg_replace('|[^a-z0-9-~+_.?@#=&;,/:%!]|i', '', $location);

    Please check it out.
    Thanks.

The topic ‘@ character problem in redirecting via the wp_redirect function’ is closed to new replies.