# Absolute URLs in RSS Feeds

**URL:** <https://discourse.gohugo.io/t/absolute-urls-in-rss-feeds/25971>\
**Category:** support\
**Created:** [June 1, 2020, 4:35pm UTC](https://discourse.gohugo.io/t/absolute-urls-in-rss-feeds/25971 "2020-06-01T16:35:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![hacdias](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hacdias/32/10272_2.png) [@hacdias](https://discourse.gohugo.io/u/hacdias)\
**Post date:** [June 2, 2020, 8:54am UTC](https://discourse.gohugo.io/t/absolute-urls-in-rss-feeds/25971/2 "2020-06-02T08:54:10Z")

</div>

To solve this I ended up using a hyper complex partial to replace all URLs by absolute ones in the `.Content` variable on feeds:

```auto
{{ $html := htmlUnescape .Content | safeHTML }}

{{ $hrefs := findRE "href=\"([^\"]*)\"" $html }}
{{ range $href := $hrefs}}
  {{ $absHref := strings.TrimPrefix "href=\"" $href }}
  {{ $absHref = strings.TrimSuffix "\"" $absHref }}
  {{ $absHref = printf "href=\"%s\"" ($absHref | absURL) }}
  {{ $html = replace $html $href $absHref }}
{{ end }}

{{ $srcs := findRE "src=\"([^\"]*)\"" $html }}
{{ range $src := $srcs}}
  {{ $absSrc := strings.TrimPrefix "src=\"" $src }}
  {{ $absSrc = strings.TrimSuffix "\"" $absSrc }}
  {{ $absSrc = printf "src=\"%s\"" ($absSrc | absURL) }}
  {{ $html = replace $html $src $absSrc }}
{{ end }}

{{ $srcset := findRE "srcset=\"([^\"]*)\"" $html }}
{{ range $set := $srcset}}
  {{ $parts := strings.TrimPrefix "srcset=\"" $set }}
  {{ $parts = strings.TrimSuffix "\"" $parts }}
  {{ $parts = split $parts "," }}
  {{ $newSrcset := slice }}
  {{ range $part := $parts }}
    {{ $part = $part | replaceRE "^\\s*(.*)\\s*$" "$1" }}
    {{ $lg := split $part " " }}
    {{ $href := index $lg 0 | absURL }}
    {{ $size := index $lg 1 }}
    {{ $newSrcset = $newSrcset | append (printf "%s %s" $href $size) }}
  {{ end }}
  {{ $newSrcset = delimit $newSrcset ", " }}
  {{ $newSrcset = printf "srcset=\"%s\"" $newSrcset }}
  {{ $html = replace $html $set $newSrcset }}
{{ end }}

{{ return $html }}

```

---

_[View the full topic](https://discourse.gohugo.io/t/absolute-urls-in-rss-feeds/25971)._
