Make WordPress Core

Ticket #33821: add_canonical_port_check.patch

File add_canonical_port_check.patch, 1.1 KB (added by willshouse, 10 years ago)

add canonical port check

  • canonical.php

    From 7039b0ff451ec27eda6788f8ba72fea124d53258 Mon Sep 17 00:00:00 2001
    From: clarkewd <clarkewd@users.noreply.github.com>
    Date: Thu, 10 Sep 2015 23:15:00 -0400
    Subject: [PATCH] add_canonical_port_check
    
    ---
     canonical.php | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)
    
    diff --git a/canonical.php b/canonical.php
    index f75a72e..3068105 100644
    a b function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    6363                // build the URL in the address bar
    6464                $requested_url  = is_ssl() ? 'https://' : 'http://';
    6565                $requested_url .= $_SERVER['HTTP_HOST'];
     66
     67                // if a server port is set
     68                if(isset($_SERVER['SERVER_PORT']))
     69                {
     70                        // if there is not already a port in the hostname
     71                        if(strpos($_SERVER['HTTP_HOST'], ':') == false)
     72                        {
     73                                // and if the port is a non-standard port
     74                                if( ! in_array(trim($_SERVER['SERVER_PORT']), array('443','80') ) )
     75                                {
     76                                        // then explicitly add it to the URL that we are building
     77                                        $requested_url .= ':'.$_SERVER['SERVER_PORT'];
     78                                }
     79                        }
     80                }
     81
    6682                $requested_url .= $_SERVER['REQUEST_URI'];
    6783        }
    6884