Make WordPress Core

Ticket #34353: 34353.2.diff

File 34353.2.diff, 1.4 KB (added by oglekler, 12 months ago)
  • src/wp-includes/canonical.php

    diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php
    index a02ab793cee3..68a33255b821 100644
    a b function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    6363                return;
    6464        }
    6565
    66         if ( ! $requested_url && isset( $_SERVER['HTTP_HOST'] ) ) {
     66        // www.example.com vs. example.com
     67        $user_home = parse_url( home_url('/') );
     68
     69        if ( ! $requested_url ) {
    6770                // Build the URL in the address bar.
    68                 $requested_url  = is_ssl() ? 'https://' : 'http://';
    69                 $requested_url .= $_SERVER['HTTP_HOST'];
     71                $requested_url = is_ssl() ? 'https://' : 'http://';
     72                if ( isset( $_SERVER['HTTP_HOST'] ) ) {
     73                        $requested_url .= $_SERVER['HTTP_HOST'];
     74                } else {
     75                        // Fallback for http1.0 where requested host and port are unknown
     76                        // In this case correct redirect no-www <=> yes-www is not possible
     77                        $requested_url .= $user_home['host'];
     78                        if ( ! empty( $user_home['port'] ) ) {
     79                                $requested_url .= ':' . $user_home['port'];
     80                        }
     81                }
    7082                $requested_url .= $_SERVER['REQUEST_URI'];
    7183        }
    7284
    function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    570582                $redirect = parse_url( $redirect_url );
    571583        }
    572584
    573         // www.example.com vs. example.com
    574         $user_home = parse_url( home_url() );
    575 
    576585        if ( ! empty( $user_home['host'] ) ) {
    577586                $redirect['host'] = $user_home['host'];
    578587        }