Chuyển hướng đến www WordPress

Bạn đang rời khỏi WordPress. com? . báo chí. com (cũng như tất cả các liên kết cố định của bạn) vào tên miền mới của bạn?

Thay vào đó, bạn có muốn trỏ một tên miền mà bạn đã sở hữu tới một WordPress không. trang com?

Mục lục

Bắt đầu

Chọn một trang web để chuyển hướng từ màn hình này. Sau khi bạn chọn một trang web, hãy nhập tên miền hoặc địa chỉ mới mà bạn muốn dùng WordPress. lưu lượng truy cập com sẽ được chuyển hướng. Nhập URL của trang web đích vào trường trống và nhấp vào nút màu xanh lam có nội dung Go

Chuyển hướng đến www WordPress

Bạn sẽ được yêu cầu xác nhận giao dịch mua và sẽ được thực hiện qua quy trình thanh toán. Khi thanh toán đã hoàn tất, bạn sẽ thấy thông báo xác nhận trên màn hình. Bạn sẽ có thể kiểm tra hoặc thay đổi cài đặt chuyển hướng từ trang Miền

Sau khi mua, Chuyển hướng trang web sẽ cần được đặt làm Miền chính. Bạn có thể chuyển miền chính của trang web của mình bằng cách đi tới Nâng cấp → Miền, nhấp vào … bên cạnh miền và chọn tạo miền chính

  • Chuyển hướng trang web sẽ chỉ trỏ đến URL không phải SSL (
    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    2). Nếu bạn đã thiết lập SSL trên trang web mà bạn đang chuyển hướng đến, chuyển hướng http-to-https sẽ được xử lý ở cuối trang web đó
  • Để Chuyển hướng Trang hoạt động chính xác, các liên kết cố định trên trang mới (trang bạn đang chuyển hướng đến) phải khớp với các liên kết tại WordPress. com. WordPress. com sử dụng cấu trúc permalink sau.
    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    3. Nếu trang web mới không sử dụng cùng cấu trúc, một số khách truy cập có thể thấy thông báo lỗi
  • Nếu bạn đã thêm blog của mình vào thư mục con như
    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    4, hãy nhớ chỉ định url blog đầy đủ (
    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    5)
  • Chuyển hướng trang web có thể được sử dụng với tên miền hoặc đường dẫn thư mục nhưng không phải với các tệp hoặc trang riêng lẻ. Ví dụ
    • VÂNG.
      function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
      	global $is_IIS;
      
      	/**
      	 * Filters the redirect location.
      	 *
      	 * @since 2.1.0
      	 *
      	 * @param string $location The path or URL to redirect to.
      	 * @param int    $status   The HTTP response status code to use.
      	 */
      	$location = apply_filters( 'wp_redirect', $location, $status );
      
      	/**
      	 * Filters the redirect HTTP response status code to use.
      	 *
      	 * @since 2.3.0
      	 *
      	 * @param int    $status   The HTTP response status code to use.
      	 * @param string $location The path or URL to redirect to.
      	 */
      	$status = apply_filters( 'wp_redirect_status', $status, $location );
      
      	if ( ! $location ) {
      		return false;
      	}
      
      	if ( $status < 300 || 399 < $status ) {
      		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
      	}
      
      	$location = wp_sanitize_redirect( $location );
      
      	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
      		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
      	}
      
      	/**
      	 * Filters the X-Redirect-By header.
      	 *
      	 * Allows applications to identify themselves when they're doing a redirect.
      	 *
      	 * @since 5.1.0
      	 *
      	 * @param string $x_redirect_by The application doing the redirect.
      	 * @param int    $status        Status code to use.
      	 * @param string $location      The path to redirect to.
      	 */
      	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
      	if ( is_string( $x_redirect_by ) ) {
      		header( "X-Redirect-By: $x_redirect_by" );
      	}
      
      	header( "Location: $location", true, $status );
      
      	return true;
      }
      
      6
    • Không ổn.
      function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
      	global $is_IIS;
      
      	/**
      	 * Filters the redirect location.
      	 *
      	 * @since 2.1.0
      	 *
      	 * @param string $location The path or URL to redirect to.
      	 * @param int    $status   The HTTP response status code to use.
      	 */
      	$location = apply_filters( 'wp_redirect', $location, $status );
      
      	/**
      	 * Filters the redirect HTTP response status code to use.
      	 *
      	 * @since 2.3.0
      	 *
      	 * @param int    $status   The HTTP response status code to use.
      	 * @param string $location The path or URL to redirect to.
      	 */
      	$status = apply_filters( 'wp_redirect_status', $status, $location );
      
      	if ( ! $location ) {
      		return false;
      	}
      
      	if ( $status < 300 || 399 < $status ) {
      		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
      	}
      
      	$location = wp_sanitize_redirect( $location );
      
      	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
      		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
      	}
      
      	/**
      	 * Filters the X-Redirect-By header.
      	 *
      	 * Allows applications to identify themselves when they're doing a redirect.
      	 *
      	 * @since 5.1.0
      	 *
      	 * @param string $x_redirect_by The application doing the redirect.
      	 * @param int    $status        Status code to use.
      	 * @param string $location      The path to redirect to.
      	 */
      	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
      	if ( is_string( $x_redirect_by ) ) {
      		header( "X-Redirect-By: $x_redirect_by" );
      	}
      
      	header( "Location: $location", true, $status );
      
      	return true;
      }
      
      7

Vô hiệu hóa chuyển hướng

Nếu bạn muốn tắt chuyển hướng một lúc nhưng không muốn xóa nó, hãy đặt WordPress mặc định của bạn. địa chỉ com địa chỉ chính của trang web của bạn thay vì chuyển hướng. Bạn có thể chuyển miền chính của trang web của mình bằng cách đi tới Nâng cấp → Miền, nhấp vào … bên cạnh miền và chọn tạo miền chính

Bạn có thể bật chuyển hướng bất kỳ lúc nào bằng cách quay lại màn hình này và đặt lại URL chuyển hướng của trang web thành miền chính

Xóa chuyển hướng

Để xóa chuyển hướng, chỉ cần xóa bản nâng cấp khỏi Mua hàng của bạn

Chuyển hướng đến www WordPress

Kế hoạch linh hoạt và giá cả

  • Miễn phí

    Chuyển hướng đến www WordPress

    tốt nhất cho sinh viên

  • Cá nhân

    Tốt nhất cho người có sở thích

  • Phần thưởng

    Tốt nhất cho dịch giả tự do

  • Kinh doanh

    Tốt nhất cho các doanh nghiệp nhỏ

Chọn một kế hoạch

Vẫn còn bối rối?

Liên hệ hỗ trợ

Giúp chúng tôi cải tiến

Chúng tôi luôn tìm cách cải thiện tài liệu của mình. Nếu trang này không trả lời câu hỏi của bạn hoặc khiến bạn muốn biết thêm, hãy cho chúng tôi biết. Chúng tôi thích nghe phản hồi của bạn. Để được hỗ trợ, vui lòng sử dụng diễn đàn hoặc liên hệ với mẫu hỗ trợ. Cảm ơn

Ghi chú. wp_redirect() không tự động thoát và hầu như luôn được theo sau bởi lệnh gọi tới

if ( wp_redirect( $url ) ) {
    exit;
}
8

wp_redirect( $url );
exit;

Việc thoát cũng có thể được thao tác có chọn lọc bằng cách sử dụng wp_redirect() làm điều kiện
kết hợp với bộ lọc ‘wp_redirect’ và ‘wp_redirect_location’.

if ( wp_redirect( $url ) ) {
    exit;
}

if ( wp_redirect( $url ) ) {
    exit;
}
9 chuỗi Bắt buộc

Đường dẫn hoặc URL để chuyển hướng đến

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
0 int Tùy chọn

Mã trạng thái phản hồi HTTP để sử dụng. Mặc định

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
1 (Đã tạm thời di chuyển)

Mặc định.

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
2

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
3 chuỗi Tùy chọn

Ứng dụng thực hiện chuyển hướng. Mặc định

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
4

Mặc định.

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
4


bool Sai nếu chuyển hướng bị hủy, đúng nếu không.


Tập tin.

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
6. Xem tất cả tài liệu tham khảo

function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}


apply_filters ( 'wp_redirect', chuỗi $location, int $status )

Lọc vị trí chuyển hướng

apply_filters ( 'wp_redirect_status', int $status, string $location )

Lọc mã trạng thái phản hồi HTTP chuyển hướng để sử dụng

apply_filters ( 'x_redirect_by', chuỗi $x_redirect_by, int $status, string $location )

Lọc tiêu đề X-Redirect-By


UsesUsesDescriptionwp_sanitize_redirect() wp-includes/pluggable. php

Vệ sinh URL để sử dụng trong chuyển hướng

status_header() wp-gồm/hàm. php

Đặt tiêu đề trạng thái HTTP

__() wp-includes/l10n. php

Truy xuất bản dịch của $text

wp_die() wp-gồm/hàm. php

Giết thực thi WordPress và hiển thị trang HTML với thông báo lỗi

apply_filters() wp-gồm/plugin. php

Gọi các chức năng gọi lại đã được thêm vào hook bộ lọc


ByUsed ByDescriptiondo_favicon() được sử dụng wp-gồm/hàm. php

Hiển thị biểu tượng yêu thích. nội dung tệp ico

WP_Recovery_Mode_Link_Service. handle_begin_link() wp-includes/class-wp-recovery-mode-link-service. php

Vào chế độ khôi phục khi người dùng truy cập wp-login. php với liên kết chế độ khôi phục hợp lệ

resume_theme() wp-admin/includes/theme. php

Cố gắng tiếp tục một chủ đề duy nhất

resume_plugin() wp-admin/gồm/plugin. php

Cố gắng tiếp tục một plugin duy nhất

wp_media_attach_action() wp-admin/includes/media. php

Đóng gói logic cho các hành động Đính kèm/Gỡ bỏ

WP_List_Table. set_pagination_args() wp-admin/includes/class-wp-list-table. php

Một phương thức nội bộ đặt tất cả các đối số phân trang cần thiết

wp_dashboard_setup() wp-admin/includes/dashboard. php

Đăng ký widget bảng điều khiển

activate_plugin() wp-admin/gồm/plugin. php

Cố gắng kích hoạt plugin trong “sandbox” và chuyển hướng thành công

redirect_post() wp-admin/includes/post. php

Chuyển hướng đến trang trước

do_dismiss_core_update() wp-admin/update-core. php

Loại bỏ một bản cập nhật cốt lõi

do_undismiss_core_update() wp-admin/update-core. php

Bỏ loại bỏ một bản cập nhật cốt lõi

WP_Customize_Manager. after_setup_theme() wp-includes/class-wp-customize-manager. php

Gọi lại để xác thực một chủ đề sau khi nó được tải

spawn_cron() wp-includes/cron. php

Gửi yêu cầu chạy cron thông qua yêu cầu HTTP không dừng tải trang

wp_safe_redirect() wp-includes/pluggable. php

Thực hiện chuyển hướng (cục bộ) an toàn, sử dụng wp_redirect()

auth_redirect() wp-includes/pluggable. php

Kiểm tra xem người dùng đã đăng nhập chưa, nếu không, nó sẽ chuyển hướng họ đến trang đăng nhập

wp_old_slug_redirect() wp-gồm/truy vấn. php

Chuyển hướng sên cũ đến permalink chính xác

wp_not_install() wp-gồm/tải. php

Chuyển hướng đến trình cài đặt nếu WordPress chưa được cài đặt

wp_redirect_admin_locations() wp-includes/canonical. php

Chuyển hướng nhiều URL tốc ký đến quản trị viên

redirect_canonical() wp-includes/canonical. php

Chuyển hướng các liên kết đến URL thích hợp dựa trên url của trang web

maybe_redirect_404() wp-gồm/ms-functions. php

Sửa chuyển hướng 404 khi NOBLOGREDIRECT được xác định

wpmu_admin_do_redirect() wp-includes/ms-deprecated. php

Chuyển hướng người dùng dựa trên đối số $_GET hoặc $_POST


ChangelogVersionDescription5. 4. 0 Trên mã trạng thái không hợp lệ, wp_die() được gọi. 5. 1. 0 Tham số
function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
	global $is_IIS;

	/**
	 * Filters the redirect location.
	 *
	 * @since 2.1.0
	 *
	 * @param string $location The path or URL to redirect to.
	 * @param int    $status   The HTTP response status code to use.
	 */
	$location = apply_filters( 'wp_redirect', $location, $status );

	/**
	 * Filters the redirect HTTP response status code to use.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $status   The HTTP response status code to use.
	 * @param string $location The path or URL to redirect to.
	 */
	$status = apply_filters( 'wp_redirect_status', $status, $location );

	if ( ! $location ) {
		return false;
	}

	if ( $status < 300 || 399 < $status ) {
		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
	}

	$location = wp_sanitize_redirect( $location );

	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
	}

	/**
	 * Filters the X-Redirect-By header.
	 *
	 * Allows applications to identify themselves when they're doing a redirect.
	 *
	 * @since 5.1.0
	 *
	 * @param string $x_redirect_by The application doing the redirect.
	 * @param int    $status        Status code to use.
	 * @param string $location      The path to redirect to.
	 */
	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
	if ( is_string( $x_redirect_by ) ) {
		header( "X-Redirect-By: $x_redirect_by" );
	}

	header( "Location: $location", true, $status );

	return true;
}
3 đã được thêm vào.
1. 5. 1Giới thiệu.

  1. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. 35Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi J. D. Bụi bẩn

    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    8 không xác thực rằng
    if ( wp_redirect( $url ) ) {
        exit;
    }
    9 là tham chiếu đến máy chủ lưu trữ hiện tại. Điều này có nghĩa là chức năng này dễ bị chuyển hướng mở nếu bạn chuyển cho nó một
    if ( wp_redirect( $url ) ) {
        exit;
    }
    9 do người dùng cung cấp. Vì lý do này, cách tốt nhất là luôn sử dụng
    wp_redirect( $url );
    exit;
    61 để thay thế, vì nó sẽ sử dụng
    wp_redirect( $url );
    exit;
    62 để đảm bảo rằng
    if ( wp_redirect( $url ) ) {
        exit;
    }
    9 đề cập đến máy chủ lưu trữ hiện tại. Chỉ sử dụng
    function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    	global $is_IIS;
    
    	/**
    	 * Filters the redirect location.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $location The path or URL to redirect to.
    	 * @param int    $status   The HTTP response status code to use.
    	 */
    	$location = apply_filters( 'wp_redirect', $location, $status );
    
    	/**
    	 * Filters the redirect HTTP response status code to use.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   The HTTP response status code to use.
    	 * @param string $location The path or URL to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location ) {
    		return false;
    	}
    
    	if ( $status < 300 || 399 < $status ) {
    		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    	}
    
    	$location = wp_sanitize_redirect( $location );
    
    	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
    		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    	}
    
    	/**
    	 * Filters the X-Redirect-By header.
    	 *
    	 * Allows applications to identify themselves when they're doing a redirect.
    	 *
    	 * @since 5.1.0
    	 *
    	 * @param string $x_redirect_by The application doing the redirect.
    	 * @param int    $status        Status code to use.
    	 * @param string $location      The path to redirect to.
    	 */
    	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    	if ( is_string( $x_redirect_by ) ) {
    		header( "X-Redirect-By: $x_redirect_by" );
    	}
    
    	header( "Location: $location", true, $status );
    
    	return true;
    }
    
    8 khi bạn đang cố gắng chuyển hướng cụ thể đến một trang web khác và sau đó bạn có thể mã hóa cứng URL

    wp_redirect( $url );
    exit;
    6

    Đăng nhập để thêm phản hồi
  2. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. 10Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi Codex

    ví dụ

    if ( wp_redirect( $url ) ) {
        exit;
    }
    1

    Chuyển hướng cũng có thể là bên ngoài và/hoặc sử dụng mã “Đã di chuyển vĩnh viễn”

    if ( wp_redirect( $url ) ) {
        exit;
    }
    2

    Mã bên dưới chuyển hướng đến URL bài đăng gốc có thể được sử dụng để chuyển hướng các trang đính kèm trở lại trang gốc

    if ( wp_redirect( $url ) ) {
        exit;
    }
    3

    Đăng nhập để thêm phản hồi
  3. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. 6Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi KZeni

    Trừ khi điều này được vá để thực hiện điều này một cách tự nhiên trong tương lai, hãy chắc chắn bao gồm

    wp_redirect( $url );
    exit;
    65 trước
    wp_redirect( $url );
    exit;
    66 nếu bạn muốn đảm bảo rằng trình duyệt của khách truy cập không lưu kết quả trang chuyển hướng vào bộ nhớ cache (thậm chí có thể xảy ra khi điều này được đặt để sử dụng chuyển hướng 302

    Ví dụ: điều này có thể có vấn đề khi được sử dụng để chuyển hướng đến trang đăng nhập khi cố gắng truy cập nội dung được bảo vệ vì sau đó khách truy cập có thể đăng nhập và thấy rằng họ vẫn được đưa trở lại trang đăng nhập khi cố gắng quay lại trang đó. . ) Có

    wp_redirect( $url );
    exit;
    65 trước khi chuyển hướng sẽ ngăn sự cố tiềm ẩn này

    • Ticket #50422 đang tìm cách giải quyết vấn đề này một cách tự nhiên cho các phiên bản tương lai của WordPress, vì vậy điều này có thể không bắt buộc trong tương lai, nhưng điều này được khuyến khích/bắt buộc vào lúc này và sẽ không thành vấn đề nếu/khi WordPress chọn áp dụng bản cập nhật được đề xuất. — Bởi KZeni —

    • Điều này dường như khắc phục sự cố với trang đăng nhập và nội dung được bảo vệ chỉ xảy ra trong Firefox. Tôi không chắc liệu nó có lưu vào bộ đệm mạnh hơn Chrome và Edge hay không, nhưng việc thêm lệnh gọi hàm này sẽ giúp chuyển hướng đến đúng nơi một cách nhất quán. — Bởi Sarah Lewis —

    Đăng nhập để thêm phản hồi
  4. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. 5Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi yonifre

    template_redirect Hành động

    if ( wp_redirect( $url ) ) {
        exit;
    }
    7

    Đăng nhập để thêm phản hồi
  5. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. 0Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi Martin Kilarski

    if ( wp_redirect( $url ) ) {
        exit;
    }
    8

    Đăng nhập để thêm phản hồi
  6. Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú nàyKết quả bình chọn cho ghi chú này. -4Bạn phải đăng nhập để bình chọn về mức độ hữu ích của ghi chú này

    Đóng góp bởi hkkcngz

    get_permalink() chỉ thực sự hữu ích cho các trang và bài đăng đơn lẻ và chỉ hoạt động bên trong vòng lặp

    WP Chuyển hướng đến trang hiện tại

    if ( wp_redirect( $url ) ) {
        exit;
    }
    9

    • wp_redirect( $url );
      exit;
      68 mong đợi một số nguyên hoặc đối tượng
      wp_redirect( $url );
      exit;
      69 cho các tham số của nó và
      if ( wp_redirect( $url ) ) {
          exit;
      }
      10 trả về một chuỗi (URL chính như tên hàm cho biết). Để thực hiện chuyển hướng, hãy xóa cuộc gọi
      wp_redirect( $url );
      exit;
      68

      if ( wp_redirect( $url ) ) {
          exit;
      }
      0

      — Bởi crstauf —

    • Nhận xét này từ @hkkcngz ở trên có nhiều vấn đề & khía cạnh đáng ngờ.

      wp_redirect( $url );
      exit;
      68 có thể được sử dụng ở mọi nơi (không chỉ trong một vòng lặp như @hkkcngz đã nêu không chính xác). Đó là những gì sau đó được truyền dưới dạng tham số cho hàm đó (hoặc nói cách khác là sử dụng tham số mặc định [s]) có thể phụ thuộc vào việc có ở trong vòng lặp hay không. Ngoài ra, @crstauf đúng ở chỗ mã từ @hkkcngz thực sự bị hỏng trên mọi thứ vì nó không sử dụng đúng
      wp_redirect( $url );
      exit;
      68 vì nó chuyển sai loại giá trị cho tham số
      wp_redirect( $url );
      exit;
      68 với
      if ( wp_redirect( $url ) ) {
          exit;
      }
      10 cung cấp URL thay vì ID bài đăng . // nhà phát triển. báo chí. org/reference/functions/get_permalink/ (với
      wp_redirect( $url );
      exit;
      68 thì thực tế không bắt buộc gì mỗi
      if ( wp_redirect( $url ) ) {
          exit;
      }
      10 đã nhận được permalink/URL mà
      function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
      	global $is_IIS;
      
      	/**
      	 * Filters the redirect location.
      	 *
      	 * @since 2.1.0
      	 *
      	 * @param string $location The path or URL to redirect to.
      	 * @param int    $status   The HTTP response status code to use.
      	 */
      	$location = apply_filters( 'wp_redirect', $location, $status );
      
      	/**
      	 * Filters the redirect HTTP response status code to use.
      	 *
      	 * @since 2.3.0
      	 *
      	 * @param int    $status   The HTTP response status code to use.
      	 * @param string $location The path or URL to redirect to.
      	 */
      	$status = apply_filters( 'wp_redirect_status', $status, $location );
      
      	if ( ! $location ) {
      		return false;
      	}
      
      	if ( $status < 300 || 399 < $status ) {
      		wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
      	}
      
      	$location = wp_sanitize_redirect( $location );
      
      	if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
      		status_header( $status ); // This causes problems on IIS and some FastCGI setups.
      	}
      
      	/**
      	 * Filters the X-Redirect-By header.
      	 *
      	 * Allows applications to identify themselves when they're doing a redirect.
      	 *
      	 * @since 5.1.0
      	 *
      	 * @param string $x_redirect_by The application doing the redirect.
      	 * @param int    $status        Status code to use.
      	 * @param string $location      The path to redirect to.
      	 */
      	$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
      	if ( is_string( $x_redirect_by ) ) {
      		header( "X-Redirect-By: $x_redirect_by" );
      	}
      
      	header( "Location: $location", true, $status );
      
      	return true;
      }
      
      8 đang muốn. ) — Bởi KZeni —