#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: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | REST API | Version: | 4.6 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
#2
follow-up:
↓ 3
@
10 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
@
10 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@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