Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#49146 closed defect (bug) (duplicate)

Corrupted inner REST API requests.

Reported by: vavra7 Owned by:
Priority: normal Milestone:
Component: REST API Version: 4.4
Severity: normal Keywords: needs-patch
Cc: Focuses: rest-api

Description

1) Make clean installation of WordPress on http://some-wp-domain.com (just example domain - can be random)
2) Go to Settings -> General and change field "Site Address (URL)" to value "http://decoupled-frontend-domain.com". Hit "Save Changes".
3) Go to Pages -> Sample Page make a random change and hit "Update"
4) ERROR

Reason is that WordPress internal request leads to wrong address:

http://decoupled-frontend-domain.com/index.php?rest_route=%2Fwp%2Fv2%2Fpages%2F2&_locale=user

Expected is request pointing to:

http://some-wp-domain.com/index.php?rest_route=%2Fwp%2Fv2%2Fpages%2F2&_locale=user

Wordpress is using "siteurl" domain instead of "home" domain for composing inner REST API request.

Change History (5)

#1 @TimothyBlynJacobs
7 years ago

  • Component GeneralREST API
  • Focuses accessibility administration removed
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Severity criticalnormal
  • Status newclosed
  • Version 5.3.24.4

Duplicate of #37020.

Hello @vavra7, welcome to trac!

This is actually intentional behavior. If you need to change this, you can use the rest_url filter in get_rest_url.

See #42869, #46246

#2 @kosso
7 years ago

I have arrived here after having the same issue since we stopped using a 'Classic Editor' plugin and switched to Gutenberg Blocks.

I see the OP mentions "Wordpress is using the site_url host instead of the home host for composing inner REST API requests."

The way I see it is the other way around. Surely?

I thought site_url was the WordPress installation and home was the (or can be a) decoupled site on another domain, being fed by the REST API? Am I wrong?

eg: kosso.mydomain.com is my Wordpress install. local.mydomain.com is a 'decoupled' Angular site.

If I change site_url to local.mydomain.com , then wp-admin 'breaks', with errors caused by styles and scripts being loaded from the wrong domain. (eg: jQuery) ie: the decoupled one.

Also with this example, if I put kosso.mydomain.com in the home option field, my permalinks will also be pointing to the wrong (WP install) host too.

Running Wordpress 5.3.2.

Any info or pointers would be great thanks.

Last edited 7 years ago by kosso (previous) (diff)

#3 @isuke01
6 years ago

  • Resolution duplicate
  • Status closedreopened

Yes Facing same issue.
I have used WP core files inside wordpress directory so page backend is:
mysite.com/wordpress/wp-admin.

frontend:
mysite.com

Version 0, edited 6 years ago by isuke01 (next)

#4 @danielamof
6 years ago

Put this code at the end of functions.php, in your active theme. It works like a charm :) Thanks to Kelderic for the solution: https://github.com/WordPress/gutenberg/issues/1761#issuecomment-549509676

add_filter('rest_url', function($url) {
    $url = str_replace(home_url(), site_url().'/index.php', $url);
    return $url;
});

#5 @TimothyBlynJacobs
6 years ago

  • Resolutionduplicate
  • Status reopenedclosed

Duplicate of #37020.

Reclosing. Using the rest_url filter to adjust this for your particular setup is the recommended way to change this like how @danielamof has done.

Note: See TracTickets for help on using tickets.