url_set_domain

url

Changes the domain of a URL

Syntax

url_set_domain(url, domain)

Parameters

url (string)

The URL string to modify

domain (string)

The new domain to set

Returns

string

The URL with the updated domain

Examples

Input:
url_set_domain("https://old.com/path", "new.com")
Output:
"https://new.com/path"
Input:
url_set_domain("https://example.com:8080/api", "api.example.com")
Output:
"https://api.example.com:8080/api"

The url_set_domain() function replaces the domain (hostname) of a URL with a new domain, preserving the protocol, port, path, and query parameters.

Usage

Use url_set_domain() when you need to change the domain in URLs, such as migrating from one domain to another or switching between different environment domains (dev, staging, production).