WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 5 weeks ago

#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 @rachelbaker
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

@adamf321 Howdy, and thanks for the ticket. The REST API endpoints use home_url() by design for a few reasons:

  1. some endpoint data is publicly discoverable so the public facing url (aka home_url) is a better fit
  2. we use rewrites to route endpoint requests and guarantee being able to rewrite the site_url()

See: https://github.com/WP-API/WP-API/issues/259

#2 follow-up: @adamf321
4 years ago

Hey @rachelbaker ,

I think the api should use site_url() and it does. For example:

#3 in reply to: ↑ 2 @rmccue
4 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.

#4 @swissspidy
22 months ago

#46246 was marked as a duplicate.

#5 @swissspidy
22 months ago

#46246 was marked as a duplicate.

#6 @TimothyBlynJacobs
11 months ago

#49146 was marked as a duplicate.

#7 @TimothyBlynJacobs
7 months ago

#49146 was marked as a duplicate.

#8 @TimothyBlynJacobs
5 weeks ago

#40437 was marked as a duplicate.

Note: See TracTickets for help on using tickets.