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;
}
Trên cùng ↑
Thông số
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;
}
4Trên cùng ↑
Trở về
bool Sai nếu chuyển hướng bị hủy, đúng nếu không.
Trên cùng ↑
Nguồn
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;
}
Xem trên Trac Xem trên GitHub
Trên cùng ↑
móc
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
Trên cùng ↑
Có liên quan
Trên cùng ↑
công dụng
UsesUsesDescriptionwp_sanitize_redirect[] wp-includes/pluggable. phpVệ 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
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. phpGọi các chức năng gọi lại đã được thêm vào hook bộ lọc
Hiển thị thêm 3 công dụng Ẩn thêm công dụngTrên cùng ↑
Được sử dụng bởi
ByUsed ByDescriptiondo_favicon[] được sử dụng wp-gồm/hàm. phpHiể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
do_dismiss_core_update[] wp-admin/update-core. phpLoạ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
Sử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
Hiển thị thêm 16 người sử dụng Ẩn người sử dụng thêmTrên cùng ↑
Nhật ký thay đổi
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. Trên cùng ↑
Ghi chú do người dùng đóng góp
Chuyển đến ghi chú 1 nội dung 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. Grimes — 7 năm trước
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;
Chuyển đến nội dung ghi chú 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 — 7 năm trướcví 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; }
Chuyển đến nội dung ghi chú 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 — 2 năm trướcTrừ 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ồiTrên cùng ↑
Nhận xét
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 — 2 năm trước
Đ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 — 2 năm trước
Chuyển đến nội dung ghi chú 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. 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 yonifre — 4 năm trướctemplate_redirect Hành động
7Đăng nhập để thêm phản hồiif [ wp_redirect[ $url ] ] { exit; }
Chuyển đến nội dung ghi chú 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 — 1 năm trước
8Đăng nhập để thêm phản hồiif [ wp_redirect[ $url ] ] { exit; }
Chuyển đến nội dung ghi chú 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 — 2 năm trướcget_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; }
Trên cùng ↑
Nhận xét
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 — 2 năm trước
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 — 2 năm trướcfunction 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; }
Bạn có thể chuyển hướng một trang WordPress không?
Nếu bạn cuộn xuống cuối trang trong trình chỉnh sửa WordPress, bạn sẽ tìm thấy phần Cài đặt AIOSEO. Bạn cần nhấp vào tab 'Chuyển hướng'. URL nguồn đã được điền vào cho bạn. Chỉ cần nhập URL mới vào trường 'URL mục tiêu' và chọn '301 Đã di chuyển vĩnh viễn' từ menu thả xuống Loại chuyển hướngBạn có thể chuyển hướng URL đến một trang cụ thể không?
Chuyển hướng cho phép bạn chuyển tiếp khách truy cập của một URL cụ thể đến một trang khác trên trang web của bạn . Trong Công cụ trang web, bạn có thể thêm chuyển hướng bằng cách đi tới Tên miền > Chuyển hướng. Chọn tên miền mong muốn, điền vào URL bạn muốn chuyển hướng đến tên miền khác và thêm URL của trang đích mới.