On this page
rest_api_register_rewrites()
Adds REST rewrite rules.
Description
See also
Source
File: wp-includes/rest-api.php. View all references
function rest_api_register_rewrites() {
global $wp_rewrite;
add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' );
add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' );
}
Related
Uses
| Uses | Description |
|---|---|
| rest_get_url_prefix() wp-includes/rest-api.php | Retrieves the URL prefix for any API resource. |
| add_rewrite_rule() wp-includes/rewrite.php | Adds a rewrite rule that transforms a URL structure to a set of query vars. |
Used By
| Used By | Description |
|---|---|
| rest_api_init() wp-includes/rest-api.php | Registers rewrite rules for the REST API. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_api_register_rewrites