Opened 9 years ago
Last modified 5 years ago
#34800 new defect (bug)
Canonical 301 redirects go to request origin instead of site_url
Reported by: | sevcsik | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.3.1 |
Component: | Canonical | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
I have a problem with canonical redirect using a CDN setup.
Let's say we have an origin server at origin.example.com
, and the CDN at www.example.com
.
When I request https://www.example.com/page-x
, it redirects me to https://origin.example.com/page-x/
instead of https://www.example.com/page-x/
, altough both site_url
and home_url
are set to https://www.example.com
.
I suspect that Wordpress doesn't use site_url
when composing the redirect URL, it's just using the request URL with a trailing slash added (which is in fact https://origin.example.com/page-x
as the CDN translates the request).
The expected behaviour would be to either:
- use the correct absolute URL in the header, like
Location: <site_url> + <canonical_path>
- use a relative URL, like
Location: <canonical_path>
I also checked the Redirection plugin, which returns relative URLs in the 301 redirects, and those work fine with my setup.
Thanks for looking into this!
Sevcsik
Attachments (2)
Change History (5)
#1
@
9 years ago
- Keywords reporter-feedback added
- Summary changed from Wordpress canonical 301 redirects go to request origin instead of site_url to Canonical 301 redirects go to request origin instead of site_url
#2
@
9 years ago
@johnbillion, thanks for the response.
According to CloudFront docs [1], the requests to the origin server are sent with a host "set the value to the domain name of the origin that is associated with the requested object." Which is in line of my general (albeit maybe shallow) understanding of how CDNs work.
Regardless of my setup, I think using site_url()
would be more consistent with the way WordPress handles absolute URLs in general. Template functions, such as get_stylesheet_directory_uri
, or the login redirection in wp-admin
works the same way. I couldn't come up any other examples when host is used for assembling absolute URLs rather than site_url()
.
I attached a diff which solves the issue, although I don't know if it would break something else.
Cheers
[1]: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#request-custom-headers-behavior
Thanks for the ticket @sevcsik.
Can you explain why your origin server serves its site from
origin.example.com
when itshome
andsite_url
are set towww.example.com
? What's the reason that the CDN requestsorigin.example.com
instead ofwww.example.com
? This seems like a strange configuration.Normally with a reverse proxy setup such as this, the origin is served from the same host as the CDN. Is there a reason your site is setup otherwise? Any more info you could provide will help us look into this issue.