Languages: English • Italiano • (Add your language)
The "wp_redirect_status" hook allows a filter to set the HTTP status code when redirecting. It's run by the default wp_redirect()
function. The filter function is passed two arguments: the HTTP status code and redirect URL. Note that wp_redirect()
is also a "pluggable" function, meaning that plugins can override it. A function that overrides wp_redirect()
may not run this filter.
/**
* Convert HTTP/1.1-only status codes to 1.0 equivalents when using HTTP/1.0
*/
function http_status_version_downgrade($status, $location) {
static $HTTP11_to_10 = array(
203 => 200,
303 => 302, 307 => 302, /* 305 => No 1.0 equivalent ,*/
);
if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0'
&& isset($HTTP11_to_10[$status]))
{
return $HTTP11_to_10[$status];
}
return $status;
}
add_filter( 'wp_redirect_status', 'http_status_version_downgrade');
wp_redirect()
is located in wp-includes/pluggable.php
.