diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index 59e9f7931c..51658ed49c 100644
--- a/src/wp-includes/rest-api.php
+++ b/src/wp-includes/rest-api.php
@@ -616,21 +616,36 @@ function rest_handle_options_request( $response, $handler, $request ) {
 	$data     = [];
 
 	foreach ( $handler->get_routes() as $route => $endpoints ) {
-		$match = preg_match( '@^' . $route . '$@i', $request->get_route() );
+		$match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
 
 		if ( ! $match ) {
 			continue;
 		}
 
+		$args = [];
+		foreach ( $matches as $param => $value ) {
+			if ( ! is_int( $param ) ) {
+				$args[ $param ] = $value;
+			}
+		}
+
+		foreach ( $endpoints as $endpoint ) {
+			// Remove the redundant preg_match argument.
+			unset( $args[0] );
+
+			$request->set_url_params( $args );
+			$request->set_attributes( $endpoint );
+		}
+
 		$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
 		$response->set_matched_route( $route );
 		break;
 	}
 
-	$response->set_data( $data );
-
 	$response = rest_send_allow_header( $response, $handler, $request );
 
+	$response->set_data( $data );
+
 	return $response;
 }
 
