# API Retrieve Post relative URLs

**URL:** <https://meta.discourse.org/t/api-retrieve-post-relative-urls/264633>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [May 11, 2023, 10:36am UTC](https://meta.discourse.org/t/api-retrieve-post-relative-urls/264633 "2023-05-11T10:36:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bobpies](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@bobpies](https://meta.discourse.org/u/bobpies)\
**Post date:** [May 11, 2023, 10:50am UTC](https://meta.discourse.org/t/api-retrieve-post-relative-urls/264633/2 "2023-05-11T10:50:47Z")

</div>

i actually asked chat GPT the same question and got a working answer straight away

using a helper method to replace the urls inside the cooked data

```rb
def update_urls(content)
    forum_domain = 'https://forums.xxx.com'

    # Update href attributes
    content.gsub!(/href="(\/[^"]*)"/i) { |match| "href=\"#{forum_domain}#{$1}\"" }

    # Update src attributes
    content.gsub!(/src="(\/[^"]*)"/i) { |match| "src=\"#{forum_domain}#{$1}\"" }

    content
  end

```

So i’ll leave this here for anyone else - if anyone has a more elegant out of the box solution i would be interested

---

_[View the full topic](https://meta.discourse.org/t/api-retrieve-post-relative-urls/264633)._
