1--- 2title: relURL 3description: Creates a baseURL-relative URL. 4date: 2017-02-01 5publishdate: 2017-02-01 6lastmod: 2017-02-01 7categories: [functions] 8menu: 9 docs: 10 parent: "functions" 11keywords: [urls] 12signature: ["relURL INPUT"] 13workson: [] 14hugoversion: 15relatedfuncs: [absURL] 16deprecated: false 17aliases: [] 18--- 19 20Both `absURL` and `relURL` consider the configured value of `baseURL` in your site's [`config` file][configuration]. Given a `baseURL` set to `https://example.com/hugo/`: 21 22``` 23{{ "mystyle.css" | absURL }} → "https://example.com/hugo/mystyle.css" 24{{ "mystyle.css" | relURL }} → "/hugo/mystyle.css" 25{{ "http://gohugo.io/" | relURL }} → "http://gohugo.io/" 26{{ "http://gohugo.io/" | absURL }} → "http://gohugo.io/" 27``` 28 29The last two examples may look strange but can be very useful. For example, the following shows how to use `absURL` in [JSON-LD structured data for SEO][jsonld] where some of your images for a piece of content may or may not be hosted locally: 30 31{{< code file="layouts/partials/schemaorg-metadata.html" download="schemaorg-metadata.html" >}} 32<script type="application/ld+json"> 33{ 34 "@context" : "http://schema.org", 35 "@type" : "BlogPosting", 36 "image" : {{ apply .Params.images "absURL" "." }} 37} 38</script> 39{{< /code >}} 40 41The above uses the [apply function][] and also exposes how the Go template parser JSON-encodes objects inside `<script>` tags. See [the safeJS template function][safejs] for examples of how to tell Hugo not to escape strings inside of such tags. 42 43{{% note "Ending Slash" %}} 44`absURL` and `relURL` are smart about missing slashes, but they will *not* add a closing slash to a URL if it is not present. 45{{% /note %}} 46 47[apply function]: /functions/apply/ 48[configuration]: /getting-started/configuration/ 49[jsonld]: https://developers.google.com/search/docs/guides/intro-structured-data 50[safejs]: /functions/safejs 51