Make WordPress Core

Opened 3 weeks ago

Last modified 3 weeks ago

#44251 new defect (bug)

Wrong way of getting website root url when site is rewritten

Reported by: vladop Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


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( $_SERVERHTTP_HOST? ) ) {

build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url=$_SERVERHTTP_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 .= $asPartshost? ;

This 3 lines above are how I solved my problem.So I deleted this line:$requested_url=$_SERVERHTTP_HOST?; and put those 3 line above instead

Change History (2)

#1 @subrataemfluence
3 weeks ago

As far as I know web.config is used for .NET projects!

#2 @vladop
3 weeks ago

Web config is used for .NET project. I have .NET project at https://www.my-imaginary-blog-domain.com. and it's web config is used for all links on that domain. My wordpress blog is "underneath" that domain at https://www.my-imaginary-blog-domain.com/blog. but only because I rewritten it. It has to be at https://www.my-imaginary-blog-domain.com/blog but in fact it is on another server with this link:https://blog.my-imaginary-blog-domain.com/blog. You can imagine it is on this url: www.my-real-wordpress-domain.com but it has to be rewritten to: www.my-rewritten-blog-domain.com/blog. Idea here is that redirect_canonical gets site root url using HTTP_HOST variable but not site url root. They don't have to match.

Note: See TracTickets for help on using tickets.