Wordpress chuyển hướng đến trang cụ thể

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;
}

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ọ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

Trê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ả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;
}

Xem trên Trac Xem trên GitHub

Trên cùng ↑

móc

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

Trên cùng ↑

Có liên quan

Trên cùng ↑

công dụng

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

Hiển thị thêm 3 công dụng Ẩn thêm công dụng

Trên cùng ↑

Được sử dụng bởi

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

Hiển thị thêm 16 người sử dụng Ẩn người sử dụng thêm

Trê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

  1. 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

    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. 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ước

    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. 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ước

    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

    Trê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

    Đăng nhập để thêm phản hồi
  4. 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ước

    template_redirect Hành động

    if [ wp_redirect[ $url ] ] {
        exit;
    }
    7

    Đăng nhập để thêm phản hồi
  5. 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

    if [ wp_redirect[ $url ] ] {
        exit;
    }
    8

    Đăng nhập để thêm phản hồi
  6. 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ước

    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

    Trên cùng ↑

    Nhận xét

    • 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 — 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ờ.

      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 — 2 năm trước

      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ướng

      Bạ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.

Chủ Đề