Make WordPress Core


Ignore:
Timestamp:
10/14/2016 07:29:08 PM (10 years ago)
Author:
rachelbaker
Message:

REST API: Support sites with index-style permalinks in get_rest_url().

Support the index-style permalinks (http://example.com/index.php/postName) when registering the REST API rewrite rules and within the get_rest_url() function. This allows sites that do not have mod_rewrite support to have almost pretty urls and have access to their REST API endpoints.

Props kraftbj.
Fixes #38182.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r38310 r38790  
    9292 *
    9393 * @see add_rewrite_rule()
     94 * @global WP_Rewrite $wp_rewrite
    9495 */
    9596function rest_api_register_rewrites() {
     97        global $wp_rewrite;
     98
    9699        add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
    97100        add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
     101        add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
     102        add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
    98103}
    99104
     
    177182 *
    178183 * @todo Check if this is even necessary
     184 * @global WP_Rewrite $wp_rewrite
    179185 *
    180186 * @param int    $blog_id Optional. Blog ID. Default of null returns URL for current blog.
     
    189195
    190196        if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
    191                 $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
     197                global $wp_rewrite;
     198
     199                if ( $wp_rewrite->using_index_permalinks() ) {
     200                        $url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme );
     201                } else {
     202                        $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
     203                }
     204
    192205                $url .= '/' . ltrim( $path, '/' );
    193206        } else {
Note: See TracChangeset for help on using the changeset viewer.