WordPress.org

Make WordPress Core

Ticket #13909: 13909.patch

File 13909.patch, 1.7 KB (added by hakre, 9 years ago)

Better HTTP 1.1 redirect - HTML in HTTP-Body comparable to Google;

  • wp-includes/pluggable.php

     
    871871 * @param int $status Status code to use
    872872 * @return bool False if $location is not set
    873873 */
    874 function wp_redirect($location, $status = 302) {
     874function wp_redirect( $location, $status = 302 ) {
    875875        global $is_IIS;
    876876
    877         $location = apply_filters('wp_redirect', $location, $status);
    878         $status = apply_filters('wp_redirect_status', $status, $location);
     877        $location = apply_filters( 'wp_redirect', $location, $status );
     878        $status   = apply_filters( 'wp_redirect_status', $status, $location );
    879879
    880880        if ( !$location ) // allows the wp_redirect filter to cancel a redirect
    881881                return false;
    882882
    883         $location = wp_sanitize_redirect($location);
     883        $location = wp_sanitize_redirect( $location );
    884884
    885885        if ( $is_IIS ) {
    886                 header("Refresh: 0;url=$location");
     886                header( "Refresh: 0;url=$location" );
    887887        } else {
    888888                if ( php_sapi_name() != 'cgi-fcgi' )
    889889                        status_header($status); // This causes problems on IIS and some FastCGI setups
    890                 header("Location: $location", true, $status);
     890                header( "Location: $location", true, $status );
    891891        }
     892
     893        $status = (int) $status;
     894        $method = $_SERVER['REQUEST_METHOD'];
     895        $html   = 'HEAD' !== $method && (301 === $status || 302 === $status || 303 === $status || 307 === $status);
     896        if ( $html ) {
     897               
     898?>
     899<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
     900<TITLE><?php echo $status; ?> Moved</TITLE></HEAD><BODY>
     901<H1><?php echo $status; ?> Moved</H1>
     902The document has moved
     903<A HREF="<?php echo esc_attr( $location ); ?>">here</A>.
     904</BODY></HTML>
     905<?php
     906        }
    892907}
    893908endif;
    894909