Make WordPress Core

Ticket #40886: 40886.diff

File 40886.diff, 1.5 KB (added by pento, 8 years ago)
  • src/wp-includes/rest-api.php

     
    308308 * @return string Full URL to the endpoint.
    309309 */
    310310function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
     311        global $is_nginx;
    311312        if ( empty( $path ) ) {
    312313                $path = '/';
    313314        }
     
    324325                $url .= '/' . ltrim( $path, '/' );
    325326        } else {
    326327                $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
     328                // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php
     329                // To work around this, we manually add index.php to the URL, avoiding the redirect.
     330                if ( $is_nginx && 'index.php' !== substr( $url, 9 ) ) {
     331                        $url .= 'index.php';
     332                }
    327333
    328334                $path = '/' . ltrim( $path, '/' );
    329335
  • tests/phpunit/tests/rest-api.php

     
    316316                $this->set_permalink_structure( '' );
    317317                $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/?rest_route=/', get_rest_url() );
    318318
     319                // nginx requires index.php in non-pretty permalinks.
     320                global $is_nginx;
     321                $is_nginx_backup = $is_nginx;
     322                $is_nginx = true;
     323
     324                $url = get_rest_url();
     325
     326                $is_nginx = $is_nginx_backup;
     327
     328                $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/index.php?rest_route=/', $url );
    319329        }
     330
    320331        /**
    321332         * @ticket 34299
    322333         */