#37020 closed defect (bug) (invalid)
get_rest_url() returns wrong path if the site and home url's are different
Reported by: | adamf321 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.6 |
Component: | REST API | Keywords: | |
Focuses: | Cc: |
Description
Eg:
If home_url = http://mysite.com and site_url = http://mybackend.com ...
Then get_rest_url( null, 'wp/v2/pages' ) returns 'http://mysite.com/wp-json/wp/v2/pages'
It should return 'http://mybackend.com/wp-json/wp/v2/pages' (this is the actual route of the endpoint)
Change History (8)
#1
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#2
follow-up:
↓ 3
@
8 years ago
Hey @rachelbaker ,
I think the api should use site_url()
and it does. For example:
- my posts endpoint is found at: "http://lean.dev/wp-json/wp/v2/posts" (this is good, just what we want)
- however get_rest_url( null, '/wp/v2/pages' ) returns "http://localhost:8005/wp-json/wp/v2/pages"
- site_url() = "http://lean.dev",
- home_url() = "http://localhost:8005"
#3
in reply to:
↑ 2
@
8 years ago
Replying to adamf321:
I think the api should use
site_url()
and it does. For example:
I think you may have your site misconfigured? site_url()
is the location of WordPress' files and wp-admin
, home_url()
is the location of your frontend, including all rewrites, and is also where the API lives. Using home_url()
is intentional behaviour, and is required for rewrites to work.
Note: See
TracTickets for help on using
tickets.
@adamf321 Howdy, and thanks for the ticket. The REST API endpoints use
home_url()
by design for a few reasons:site_url()
See: https://github.com/WP-API/WP-API/issues/259