# get_rest_url()

URL: https://chugunov.pro/api-wordpress/functions/get_rest_url/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.4.0.

## Сигнатура

```php
get_rest_url( int|null $blog_id = null, string $path = '/', string $scheme = 'rest' ): string
```

## Описание

Примечание: возвращаемый URL НЕ экранирован.

## Параметры

- `$blog_id` `int|null` — необязательный, по умолчанию `null`. ID блога. Значение по умолчанию null возвращает URL для текущего блога.
- `$path` `string` — необязательный, по умолчанию `'/'`. Маршрут REST. Значение по умолчанию — '/'.
- `$scheme` `string` — необязательный, по умолчанию `'rest'`. Схема очистки. Значение по умолчанию — 'rest'.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/rest-api.php:510`

```php
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
	if ( empty( $path ) ) {
		$path = '/';
	}

	$path = '/' . ltrim( $path, '/' );

	if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
		global $wp_rewrite;

		if ( $wp_rewrite->using_index_permalinks() ) {
			$url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme );
		} else {
			$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
		}

		$url .= $path;
	} else {
		$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
		/*
		 * nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
		 * To work around this, we manually add index.php to the URL, avoiding the redirect.
		 */
		if ( ! str_ends_with( $url, 'index.php' ) ) {
			$url .= 'index.php';
		}

		$url = add_query_arg( 'rest_route', $path, $url );
	}

	if ( is_ssl() && isset( $_SERVER['SERVER_NAME'] ) ) {
		// If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
		if ( parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) === $_SERVER['SERVER_NAME'] ) {
			$url = set_url_scheme( $url, 'https' );
		}
	}

	if ( is_admin() && force_ssl_admin() ) {
		/*
		 * In this situation the home URL may be http:, and `is_ssl()` may be false,
		 * but the admin is served over https: (one way or another), so REST API usage
		 * will be blocked by browsers unless it is also served over HTTPS.
		 */
		$url = set_url_scheme( $url, 'https' );
	}

	/**
	 * Filters the REST URL.
	 *
	 * Use this filter to adjust the url returned by the get_rest_url() function.
	 *
	 * @since 4.4.0
	 *
	 * @param string   $url     REST URL.
	 * @param string   $path    REST route.
	 * @param int|null $blog_id Blog ID.
	 * @param string   $scheme  Sanitization scheme.
	 */
	return apply_filters( 'rest_url', $url, $path, $blog_id, $scheme );
}
```

## История изменений

- 4.4.0 — Introduced.

## Связанные

Использует: [`rest_get_url_prefix`](https://chugunov.pro/api-wordpress/functions/rest_get_url_prefix/), [`is_ssl`](https://chugunov.pro/api-wordpress/functions/is_ssl/), [`force_ssl_admin`](https://chugunov.pro/api-wordpress/functions/force_ssl_admin/), [`set_url_scheme`](https://chugunov.pro/api-wordpress/functions/set_url_scheme/), [`get_home_url`](https://chugunov.pro/api-wordpress/functions/get_home_url/), `WP_Rewrite::using_index_permalinks`, [`get_blog_option`](https://chugunov.pro/api-wordpress/functions/get_blog_option/), [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`is_multisite`](https://chugunov.pro/api-wordpress/functions/is_multisite/), [`is_admin`](https://chugunov.pro/api-wordpress/functions/is_admin/), [`add_query_arg`](https://chugunov.pro/api-wordpress/functions/add_query_arg/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/).
Используется в: [`wp_is_local_html_output`](https://chugunov.pro/api-wordpress/functions/wp_is_local_html_output/), [`wp_default_packages_inline_scripts`](https://chugunov.pro/api-wordpress/functions/wp_default_packages_inline_scripts/), [`rest_output_rsd`](https://chugunov.pro/api-wordpress/functions/rest_output_rsd/), [`rest_output_link_wp_head`](https://chugunov.pro/api-wordpress/functions/rest_output_link_wp_head/), [`rest_output_link_header`](https://chugunov.pro/api-wordpress/functions/rest_output_link_header/), [`rest_url`](https://chugunov.pro/api-wordpress/functions/rest_url/), `WP_REST_Server::serve_request`, [`wp_default_scripts`](https://chugunov.pro/api-wordpress/functions/wp_default_scripts/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_rest_url/
