wp_redirect()重定向301跳转

目录

描述

译文

将用户重定向到一个预先制定的绝对URI。

参数

$location

(字符串)(必需)用户被重定向到的绝对URI。

默认值:None

$status

(整数)(可选)所用的状态码

默认值302

原文

Redirects the user to a specified absolute URI.

wp_redirect() 描述

用法

wp_redirect() does not exit automatically and should almost always be followed by exit. If you are going to use it in page template or any other page make sure to use the function before get_header().

wp_redirect() 用法

参数

$location

(string) (必填) The absolute URI which the user will be redirected to.

默认值: None

$status

(integer) (可选) The status code to use.

默认值: 302

wp_redirect() 参数

返回值

(bool) 

False if $location is not set, returns true otherwise.

wp_redirect() 返回值

示例

Redirects can also be external, and/or use a "Moved Permanently" code :

The code below redirects to the parent post URL which can be used to redirect attachment pages back to the parent.

wp_redirect() 示例

注意

The HTTP/1.1 status code 302 is a temporary redirect. If the page has moved permanently, use the HTTP status code 301.

wp_redirect() is a Pluggable Function

wp_redirect() 注意

历史

  • 添加于 版本: 1.5.1

wp_redirect() 历史

源文件

wp_redirect() 函数的代码位于 wp-includes/pluggable.php.

wp_redirect() 源文件

相关