url_strip_port_if_default
urlRemoves port only if it's the default for the protocol
Syntax
url_strip_port_if_default(url) Parameters
url (string) The URL string to modify
Returns
string The URL with default port removed, or unchanged if port is non-default
Examples
Input:
url_strip_port_if_default("https://example.com:443") Output:
"https://example.com" Input:
url_strip_port_if_default("https://example.com:8080") Output:
"https://example.com:8080" The url_strip_port_if_default() function removes the port number from a URL only if it matches the default port for the URL’s protocol (e.g., 80 for HTTP, 443 for HTTPS). Non-default ports are preserved.
Usage
Use url_strip_port_if_default() when you need to normalize URLs by removing redundant default ports while preserving important non-standard port information, such as creating clean canonical URLs that maintain service-specific port configurations.