Make WordPress Core

Opened 4 years ago

Last modified 2 weeks ago

#30581 assigned defect (bug)

http/https pages have different canonical URLs

Reported by: betzster Owned by: joostdevalk
Milestone: 5.0 Priority: normal
Severity: normal Version: 2.9
Component: Canonical Keywords: needs-refresh https SEO
Focuses: Cc:


If you have SSL turned on, but don't force redirect, http and https pages will have different URLs. Ideally, I think the canonical URL should always use http unless FORCE_SSL is turned on.

Even a filter for rel_canonical would be better than what we have now. Unhooking and creating your own version of rel_canonical() works, but if multiple plugins do this, you end up with multiple canonical URLs set on every page.

Related: #18660, #14458

Attachments (1)

30581.1.diff (1.1 KB) - added by peterwilsoncc 3 years ago.

Download all attachments as: .zip

Change History (14)

#1 @johnbillion
4 years ago

  • Component changed from General to Canonical
  • Milestone changed from Awaiting Review to Future Release

Note that FORCE_SSL doesn't exist yet. See #28521.

I think this can go hand in hand with #28521. There are too many gotchas if we try to automatically enforce any given scheme on a site. See #29708.

#2 @johnbillion
4 years ago

  • Version changed from trunk to 2.9

#3 @peterwilsoncc
3 years ago

30581.1.diff forces the scheme of the rel_canonical URL to match that of the home page defined in options > general.

The current behaviour remains for URLs without the http, https or relative protocols (check is taken from get_home_url).

#4 @peterwilsoncc
3 years ago

  • Keywords needs-refresh added

#5 @johnbillion
3 years ago

  • Keywords https added

#6 @newash
3 years ago

  • Keywords changed from needs-refresh, https to needs-refresh https

+1 for the filter option, it would be really nice and also non-intrusive.

#7 @joemcgill
2 years ago

Just ran into this myself. A filter would be nice, but in the mean time, forcing the site to respect the scheme set in the home option as 30581.1.diff suggests so the canonical URL doesn't change based on context.

#8 @joemcgill
2 years ago

Alternately, it looks like the approach in #36168 would be to replace the get_permalink() call with a call to a new function, get_canonical_url().

This ticket was mentioned in Slack in #core-http by joemcgill. View the logs.

22 months ago

#10 @joostdevalk
7 months ago

  • Keywords SEO added
  • Owner set to joostdevalk
  • Status changed from new to assigned

#11 @SergeyBiryukov
4 months ago

If you have SSL turned on, but don't force redirect, http and https pages will have different URLs.

Found a related issue: if you have a static home page set, it does force a redirect. Posts and other pages don't.

#12 @SergeyBiryukov
4 months ago

  • Milestone changed from Future Release to 5.0

#13 @palmiak
2 weeks ago

The filter was introduced in wp_get_canonical_url in WP 4.6. I think that adding another filter in rel_canonical would be a duplicate.

Note: See TracTickets for help on using tickets.