---
title: "getRootDomain"
description: "Extract the root domain from a URL, correctly handling compound top-level domains so subdomains collapse to their registrable base."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-root-domain"
---
# getRootDomain

> Extract the root domain from a URL, correctly handling compound top-level domains so subdomains collapse to their registrable base.

## Usage

`getRootDomain` extracts the root domain (top-level domain + second-level domain) from a URL.

```ts
import { getRootDomain } from '@movk/core'

getRootDomain('https://sub.example.com') // 'example.com'
getRootDomain('https://a.b.example.co.uk') // 'example.co.uk'
```

## API

### `getRootDomain(url)`

Get the root domain (TLD + second-level domain) from a URL.

### Parameters

**url** (`string`) *required*: The URL string.

### Returns

**returns** (`string`): The root domain, or an empty string if parsing fails.

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/parse.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
