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
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 [
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 đó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; }
- Để 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.
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ỗifunction 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; }
- Nếu bạn đã thêm blog của mình vào thư mục con như
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]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; }
- 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.
6function 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; }
- Không ổn.
7function 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; }
- VÂNG.
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
Kế hoạch linh hoạt và giá cả
Miễn phí
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ỏ
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;
}
8wp_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ọnMã trạng thái phản hồi HTTP để sử dụng. Mặc định
1 [Đã tạm thời di chuyể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;
}
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;
}
2function 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
4function 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;
}
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;
}
4bool 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ảofunction 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;
}
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
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. phpTruy xuất bản dịch của $text
wp_die[] wp-gồm/hàm. phpGiế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. phpGọi các chức năng gọi lại đã được thêm vào hook bộ lọc
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. phpVà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. phpCố gắng tiếp tục một chủ đề duy nhất
resume_plugin[] wp-admin/gồm/plugin. phpCố 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. phpMộ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. phpCố gắng kích hoạt plugin trong “sandbox” và chuyển hướng thành công
redirect_post[] wp-admin/includes/post. phpChuyển hướng đến trang trước
Loại bỏ một bản cập nhật cốt lõi
do_undismiss_core_update[] wp-admin/update-core. phpBỏ 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. phpGọi lại để xác thực một chủ đề sau khi nó được tải
spawn_cron[] wp-includes/cron. phpGử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. phpThực hiện chuyển hướng [cục bộ] an toàn, sử dụng wp_redirect[]
auth_redirect[] wp-includes/pluggable. phpKiể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. phpChuyển hướng sên cũ đến permalink chính xác
wp_not_install[] wp-gồm/tải. phpChuyể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. phpChuyển hướng nhiều URL tốc ký đến quản trị viên
redirect_canonical[] wp-includes/canonical. phpChuyể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. phpSửa chuyển hướng 404 khi NOBLOGREDIRECT được xác định
wpmu_admin_do_redirect[] wp-includes/ms-deprecated. phpChuyển hướng người dùng dựa trên đối số $_GET hoặc $_POST
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. 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 —
8 không xác thực rằngfunction 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; }
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ộtif [ 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ụngif [ wp_redirect[ $url ] ] { exit; }
61 để thay thế, vì nó sẽ sử dụngwp_redirect[ $url ]; exit;
62 để đảm bảo rằngwp_redirect[ $url ]; exit;
9 đề cập đến máy chủ lưu trữ hiện tại. Chỉ sử dụngif [ wp_redirect[ $url ] ] { exit; }
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 URLfunction 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Đăng nhập để thêm phản hồiwp_redirect[ $url ]; exit;
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ụ
1if [ wp_redirect[ $url ] ] { exit; }
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”
2if [ wp_redirect[ $url ] ] { exit; }
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
3Đăng nhập để thêm phản hồiif [ wp_redirect[ $url ] ] { exit; }
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
65 trướcwp_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 302wp_redirect[ $url ]; exit;
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ó
65 trước khi chuyển hướng sẽ ngăn sự cố tiềm ẩn nàywp_redirect[ $url ]; exit;
Đăng nhập để thêm phản hồiTicket #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 —
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
7Đăng nhập để thêm phản hồiif [ wp_redirect[ $url ] ] { exit; }
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 —
8Đăng nhập để thêm phản hồiif [ wp_redirect[ $url ] ] { exit; }
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
9if [ wp_redirect[ $url ] ] { exit; }
68 mong đợi một số nguyên hoặc đối tượngwp_redirect[ $url ]; exit;
69 cho các tham số của nó và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ọiif [ wp_redirect[ $url ] ] { exit; }
68wp_redirect[ $url ]; exit;
0if [ wp_redirect[ $url ] ] { exit; }
— Bởi crstauf —
Nhận xét này từ @hkkcngz ở trên có nhiều vấn đề & khía cạnh đáng ngờ.
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 đúngwp_redirect[ $url ]; exit;
68 vì nó chuyển sai loại giá trị cho tham sốwp_redirect[ $url ]; exit;
68 vớiwp_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ớiif [ wp_redirect[ $url ] ] { exit; }
68 thì thực tế không bắt buộc gì mỗiwp_redirect[ $url ]; exit;
10 đã nhận được permalink/URL màif [ wp_redirect[ $url ] ] { exit; }
8 đang muốn. ] — Bởi KZeni —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; }