[wp-trac] [WordPress Trac] #38182: rest_url does not support index permalinks
WordPress Trac
noreply at wordpress.org
Mon Oct 17 02:23:31 UTC 2016
#38182: rest_url does not support index permalinks
---------------------------------------------+----------------------
Reporter: kraftbj | Owner: kraftbj
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 4.7
Component: REST API | Version: 4.4
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests commit | Focuses:
---------------------------------------------+----------------------
Comment (by dd32):
@rachelbaker @kraftbj Is there any reason why extra rewrites are needed
here?
For example, it could be done like so:
{{{
add_rewrite_rule( '^' . ( $wp_rewrite->index ? $wp_rewrite->index . '/' :
'' ) . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
}}}
Sites which use that format would have something like this at present:
{{{
array (size=142)
'^wp-json/?$' => string 'index.php?rest_route=/' (length=22)
'^wp-json/(.*)?' => string 'index.php?rest_route=/$matches[1]'
(length=33)
'^index.php/wp-json/?$' => string 'index.php?rest_route=/' (length=22)
'^index.php/wp-json/(.*)?' => string 'index.php?rest_route=/$matches[1]'
(length=33)
'index.php/category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string
'index.php?category_name=$matches[1]&feed=$matches[2]' (length=52)
}}}
While I'm looking at this, any particular reason why the second rule is an
optional match? Surely `^wp-json/(.+)` makes more sense considering the
first catches an empty request.. and as all rewrite rules are anchored to
the start, the `^` carrot isn't even needed (It ultimately means PCRE is
matching on `#^^wp-json/...`)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38182#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list