2019-10-21 04:22:28 -04:00
---
title: urls.Parse
2023-05-22 10:43:12 -04:00
description: Parses a URL into a URL structure.
2019-10-21 04:22:28 -04:00
categories: [functions]
2023-10-20 03:42:39 -04:00
keywords: []
2019-10-21 04:22:28 -04:00
menu:
docs:
2023-05-22 10:43:12 -04:00
parent: functions
2023-10-20 03:42:39 -04:00
function:
aliases: []
returnType: URL
signatures: [urls.Parse URL]
relatedFunctions: []
aliases: [/functions/urls.parse]
2019-10-21 04:22:28 -04:00
---
2023-05-22 10:43:12 -04:00
The `urls.Parse` function parses a URL into a [URL structure ](https://godoc.org/net/url#URL ). The URL may be relative (a path, without a host) or absolute (starting with a [scheme]). Hugo throws an error when parsing an invalid URL.
2019-10-21 04:22:28 -04:00
2023-05-22 10:43:12 -04:00
[scheme]: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml#uri-schemes-1
2019-10-21 04:22:28 -04:00
2022-11-17 10:14:29 -05:00
```go-html-template
2023-05-22 10:43:12 -04:00
{{ $url := "https://example.org:123/foo?a=6& b=7#bar" }}
{{ $u := urls.Parse $url }}
{{ $u.IsAbs }} → true
{{ $u.Scheme }} → https
{{ $u.Host }} → example.org:123
{{ $u.Hostname }} → example.org
{{ $u.RequestURI }} → /foo?a=6& b=7
{{ $u.Path }} → /foo
{{ $u.Query }} → map[a:[6] b:[7]]
{{ $u.Query.a }} → [6]
{{ $u.Query.Get "a" }} → 6
{{ $u.Query.Has "b" }} → true
{{ $u.Fragment }} → bar
2021-10-31 08:51:51 -04:00
```