我建议您的逻辑更加健壮一些,这样,如果URL发生变化,您就不会仍然使用相同的位置参数:
function redirect_to_change_avatar() {
$request_uri = filter_input( INPUT_SERVER, \'REQUEST_URI\', FILTER_SANITIZE_STRING );
// Strpos will return boolean FALSE if the string does not match at all.
// N.B the strict === comparison:
if ( false === strpos( $request_uri, \'/profile/change-avatar/\' )) {
return;
}
wp_redirect( \'/change-avatar/\' );
exit;
}