Yoast\WP\SEO\MyYoast_Client\Domain

Resource_Indicator::normalize_trailing_slashprivate staticYoast 1.0

Strips a single trailing slash from URIs that have an authority and a root-only path, so "https://host/" and "https://host" map to the same canonical form. URIs without an authority (urn:, did:, etc.) are left alone.

Метод класса: Resource_Indicator{}

Хуков нет.

Возвращает

Строку. The URI, with the root-path trailing slash trimmed when applicable.

Использование

$result = Resource_Indicator::normalize_trailing_slash( $uri ): string;
$uri(строка) (обязательный)
A validated absolute URI.

Код Resource_Indicator::normalize_trailing_slash() Yoast 28.3

private static function normalize_trailing_slash( string $uri ): string {
	if ( \strpos( $uri, '://' ) === false ) {
		return $uri;
	}

	$after_authority = \substr( $uri, ( \strpos( $uri, '://' ) + 3 ) );
	$query_pos       = \strpos( $after_authority, '?' );
	$path_segment    = ( $query_pos === false ) ? $after_authority : \substr( $after_authority, 0, $query_pos );

	$slash_pos = \strpos( $path_segment, '/' );
	if ( $slash_pos === false ) {
		return $uri;
	}

	$path = \substr( $path_segment, $slash_pos );
	if ( $path === '/' ) {
		$prefix_end = \strpos( $uri, '/', ( \strpos( $uri, '://' ) + 3 ) );

		return \substr( $uri, 0, $prefix_end ) . ( ( $query_pos === false ) ? '' : \substr( $after_authority, $query_pos ) );
	}

	return $uri;
}