Skip to content

Administration: Use admin_url() for canonical URL#1504

Open
jefferyto wants to merge 1 commit intoWordPress:trunkfrom
jefferyto:trac-35561-admin-canonical-url
Open

Administration: Use admin_url() for canonical URL#1504
jefferyto wants to merge 1 commit intoWordPress:trunkfrom
jefferyto:trac-35561-admin-canonical-url

Conversation

@jefferyto
Copy link
Copy Markdown

Currently, wp_admin_canonical_url() uses $_SERVER['HTTP_HOST'] to build an admin page's canonical URL. This URL will point to an incorrect host if $_SERVER['HTTP_HOST'] does not match the site URL host, e.g. when Wordpress is used behind a reverse proxy.

This uses admin_url() so that the canonical URL will take the configured site URL into account.

Trac ticket: https://core.trac.wordpress.org/ticket/35561


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@hanspoo
Copy link
Copy Markdown

hanspoo commented Oct 15, 2021

Please merge this code, the problem is critical for running wordpress under a prefix / context.

Currently, wp_admin_canonical_url() uses $_SERVER['HTTP_HOST'] to build
an admin page's canonical URL. This URL will point to an incorrect host
if $_SERVER['HTTP_HOST'] does not match the site URL host, e.g. when
Wordpress is used behind a reverse proxy.

This uses admin_url() so that the canonical URL will take the configured
site URL into account.

Trac ticket: https://core.trac.wordpress.org/ticket/35561
@jefferyto jefferyto changed the base branch from master to trunk March 8, 2023 07:11
@jefferyto jefferyto force-pushed the trac-35561-admin-canonical-url branch from ffd8059 to 340b484 Compare March 8, 2023 07:12
@p4block
Copy link
Copy Markdown

p4block commented Aug 1, 2024

The patch that was eventually merged doesn't solve this problem, it's currently near-impossible to host Wordpress behind a reverse proxy that removes the subpath from the request before forwarding it to the container.
The main site works, the admin panel is the only one returning broken URLs

This fix is basically required for a k8s+wordpress setup. Some people do a filesystem symlink and don't take away the subpath at the ingress, but that hack has various real world problems once you start getting involved with it, and it's a hack anyway.

Code-wide I think it would be better to replicate the behavior of the main site and use siteurl, although I understand that the admin page has to have some kind of fallback functionality when siteurl is wrong.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 1, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @hanspoo, @p4block.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jefferyto.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants