[wp-trac] [WordPress Trac] #44251: Wrong way of getting website root url when site is rewritten

WordPress Trac noreply at wordpress.org
Mon May 28 13:11:44 UTC 2018

#44251: Wrong way of getting website root url when site is rewritten
 Reporter:  vladop        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
 I have my wordpress setup on IIS and it is on https://blog.my-imaginary-
 blog-domain.com/blog. This is "real" address of my website. However user
 see this url https://www.my-imaginary-blog-domain.com/blog. Every page
 works but my homepage goes in redirect loop. I made changes to my
 wordpress settings and I setup that my site url is https://www.my-
 imaginary-blog-domain.com/blog. Inside web.config file of https://www.my-
 imaginary-blog-domain.com project I made rewrite rule. This is about my
 setup. Now about where is problem. Problem is in wp_includes/canonical.php
 file inside redirect_canonical method:
 if ( ! $requested_url && isset( $_SERVER['HTTP_HOST'] ) ) {
                 // build the URL in the address bar
                 $requested_url  = is_ssl() ? 'https://' : 'http://';
                 $requested_url=$_SERVER['HTTP_HOST'] //this is wrong in my
 opinion, this returns // https://blog.my-imaginary-blog-domain.com/blog,
 and not https://www.my-imaginary-blog-domain.com, causing problem of
 infinite redirection loop, probably some code compares this incoreectly
 made $requested_url variable with something else
                  $sURL    = site_url();
         $asParts = parse_url( $sURL );
                 $requested_url .= $asParts['host'] ;

 This 3 lines above are how I solved my problem.So I deleted this
 line:$requested_url=$_SERVER['HTTP_HOST']; and put those 3 line above

Ticket URL: <https://core.trac.wordpress.org/ticket/44251>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list