Skip to content

fix: support rest_route query-parameter API root for plain-permalink sites#1410

Closed
mmustafasenoglu wants to merge 1 commit into
Automattic:trunkfrom
mmustafasenoglu:trunk
Closed

fix: support rest_route query-parameter API root for plain-permalink sites#1410
mmustafasenoglu wants to merge 1 commit into
Automattic:trunkfrom
mmustafasenoglu:trunk

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Summary

When WordPress uses plain permalinks, it advertises the REST API root as a query-parameter form:

Link: <https://example.com/index.php?rest_route=/>; rel="https://api.w.org/"

Previously, WpOrgSiteApiUrlResolver::resolve would path-extend this URL, producing non-routing URLs:

https://example.com/index.php/wp/v2/users/me?rest_route=/

WordPress ignores the path segments and always honors rest_route=/, returning the API index for every endpoint (or 404).

Fix

This fix detects the rest_route query parameter in the API root URL and builds endpoint URLs by setting the rest_route value instead:

https://example.com/index.php?rest_route=/wp/v2/users/me

Changes

  • Modified WpOrgSiteApiUrlResolver::resolve in wp_api/src/request/endpoint.rs
  • Added build_route_path helper method
  • Added 4 new tests covering both rest_route and standard path forms

Testing

All 741 existing tests pass. 4 new tests added:

  • test_resolve_with_rest_route_query_param
  • test_resolve_with_rest_route_trailing_slash
  • test_resolve_without_rest_route
  • test_build_route_path

Related Issues

…sites

When WordPress uses plain permalinks, it advertises the REST API root as
a query-parameter form:

  https://example.com/index.php?rest_route=/

Previously, WpOrgSiteApiUrlResolver::resolve would path-extend this URL,
producing non-routing URLs like:

  https://example.com/index.php/wp/v2/users/me?rest_route=/

WordPress ignores the path segments and always honors rest_route=/,
returning the API index for every endpoint.

This fix detects the rest_route query parameter in the API root URL and
builds endpoint URLs by setting the rest_route value instead:

  https://example.com/index.php?rest_route=/wp/v2/users/me

Fixes Automattic#1366
Fixes wordpress-mobile/WordPress-iOS#25604

Signed-off-by: mustafasenoglu <mustafasenoglu@users.noreply.github.com>
Signed-off-by: Mustafa Senoglu <mustafa@senoglu.local>
@crazytonyli

Copy link
Copy Markdown
Contributor

Thanks for the pull request. There is an existing PR #1369 that addresses the issue. I'll close this one for now.

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

Labels

None yet

Projects

None yet

2 participants