#34302 closed defect (bug) (invalid)
get_rest_url() should not include a trailing slash by default
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Core's various *_url()
functions return URLs without a trailing slash unless the $path
argument specifies one. get_rest_url()
is the exception as it includes a trailing slash by default when no $path
is specified.
echo get_home_url() // http://example.com echo get_rest_url() // http://example.com/wp-json/
This creates a problem when a REST API client requests http://example.com/wp-json/
to retrieve a list of routes and then concatenates one of the available routes onto the REST API endpoint, resulting in a double slash in the path, which in turn results in a 404 when requested.
An example of an affected client is the REST API Console plugin.
Unfortunately this also affects some of the internals of the REST API.
Patch in progress.
Change History (3)
This ticket was mentioned in Slack in #core-restapi by rmccue. View the logs.
9 years ago
#3
@
9 years ago
Related:
https://github.com/WP-API/WP-API/issues/1505 - Require the $namespace argument in register_rest_route()
and
https://github.com/WP-API/WP-API/issues/1504 - Separate out the namespace from the path in rest_url/get_rest_url functions
This is intentional; see https://github.com/WP-API/WP-API/pull/1426 and https://github.com/WP-API/WP-API/pull/1467
Basically, the REST API works a bit differently. Rather than default to no
$path
, we default to the index at/
. Without a route is an error, since there's no empty-string route (we obviously treat it as '/' to avoid errors, but you shouldn't ever do that).$path
is probably the wrong thing to call it, and I think we want to add$namespace
in as well, so the eventual signature should probably actually be:I'll open a new ticket for that.