fix: support rest_route query-parameter API root for plain-permalink sites#1410
Closed
mmustafasenoglu wants to merge 1 commit into
Closed
fix: support rest_route query-parameter API root for plain-permalink sites#1410mmustafasenoglu wants to merge 1 commit into
mmustafasenoglu wants to merge 1 commit into
Conversation
…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>
Contributor
|
Thanks for the pull request. There is an existing PR #1369 that addresses the issue. I'll close this one for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When WordPress uses plain permalinks, it advertises the REST API root as a query-parameter form:
Previously,
WpOrgSiteApiUrlResolver::resolvewould path-extend this URL, producing non-routing URLs: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_routequery parameter in the API root URL and builds endpoint URLs by setting therest_routevalue instead:Changes
WpOrgSiteApiUrlResolver::resolveinwp_api/src/request/endpoint.rsbuild_route_pathhelper methodrest_routeand standard path formsTesting
All 741 existing tests pass. 4 new tests added:
test_resolve_with_rest_route_query_paramtest_resolve_with_rest_route_trailing_slashtest_resolve_without_rest_routetest_build_route_pathRelated Issues