diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index 6f4f869238c76b6967eb523d4452556845f84f3b..f4a83138e4c5ad4cbbc4b3cc20060dbc581d16c1 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -91,6 +91,19 @@ class URLGenerator implements IURLGenerator {
 		return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
 	}
 
+	public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string {
+		$route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false);
+
+		if (strpos($route, '/index.php') === 0) {
+			$route = substr($route, 10);
+		}
+
+		$route = substr($route, 7);
+		$route = '/ocs/v2.php' . $route;
+
+		return $this->getAbsoluteURL($route);
+	}
+
 	/**
 	 * Creates an url
 	 * @param string $app app
diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php
index ebf35967551cc9b72c916b7e0c03763b72789823..368f65fe4c10d953586e94c58700853686f9c1fd 100644
--- a/lib/public/IURLGenerator.php
+++ b/lib/public/IURLGenerator.php
@@ -50,6 +50,14 @@ interface IURLGenerator {
 	 */
 	public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string;
 
+	/**
+	 * @param string $routeName
+	 * @param array $arguments
+	 * @return string
+	 * @since 15.0.0
+	 */
+	public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string;
+
 	/**
 	 * Returns an URL for an image or file
 	 * @param string $appName the name of the app
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 340c9c7082d219404affbbf5020319b9b963968a..0e50f4d92ecf8fd908de37046c3b1dec8a9a2f0e 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -162,4 +162,22 @@ class UrlGeneratorTest extends \Test\TestCase {
 		$this->assertEquals($expected, $actual);
 	}
 
+	/**
+	 * @dataProvider provideOCSRoutes
+	 */
+	public function testLinkToOCSRouteAbsolute(string $route, string $expected) {
+		$this->mockBaseUrl();
+		\OC::$WEBROOT = '/nextcloud';
+		$result = $this->urlGenerator->linkToOCSRouteAbsolute($route);
+		$this->assertEquals($expected, $result);
+	}
+
+	public function provideOCSRoutes() {
+		return [
+			['core.OCS.getCapabilities', 'http://localhost/nextcloud/ocs/v2.php/cloud/capabilities'],
+			['core.WhatsNew.dismiss', 'http://localhost/nextcloud/ocs/v2.php/core/whatsnew'],
+		];
+	}
+
+
 }