<p>I would question the need to have relative URLs to begin with.</p>

<p>As <a href="https://craftcms.stackexchange.com/a/13876/1016">Brad mentions</a>, Craft neatly solves the multi-environment problem for you.</p>

<p>If you come from an environment like WordPress where it makes absolute URLs for you and then you end up having to do a find-replace on the content when switching environments (since there's no "built-in" way to do it), I can see where your co-worker might think relative is the way to go. However, even WP has good reason to do so.</p>

<p>Back before content management systems, relative URLs were probably the way to go because they are easier to code by hand; if you used conventions like "../" your pages also worked locally. Now with systems like Craft and local testing servers, creating links within content is much more consistent.</p>

<p>Craft even has a find/replace tool in the CP if you want to make sure those staging/production URLs absolutely get switched over in the database as well.</p>

<p>Speaking of consistency, google wants you to be as efficient as possible. From an SEO perspective, this <a href="https://moz.com/blog/relative-vs-absolute-urls-whiteboard-friday" rel="nofollow noreferrer">moz post</a> goes over the pros and cons of relative vs absolute but a few points worth summarizing:</p>

<ul>
<li><p><strong>Scrapers</strong> can be a big problem stealing your content. Absolute URLs make it a bit more difficult for the laziest of them. </p></li>
<li><p>By using things like <code>rel="canonical"</code> and letting Craft spit out your main base URL consistently, you can help avoid <strong>duplicate content</strong> issues.</p></li>
</ul>

<p><a href="https://yoast.com/dev-blog/relative-urls-issues/" rel="nofollow noreferrer">Yoast</a> gives some thoughts on this as well but I'll leave you with one takeaway:</p>

<blockquote>
  <p>The few minutes a developer might save by using relative URLs are offset by countless hours an SEO might be spending to solve the issues caused.</p>
</blockquote>

CC BY-SA 4.0
2021-07-27T12:56:45.517Z
so you don't answer the question, reject the premise and reason with an article that basically states "it's bad for seo if you do it wrong" and present that as an answer to the question you rejected.
scones
CC BY-SA 4.0
2021-07-27T15:57:43.163Z
@scones: Sorry you feel this didn't answer the question but clearly the OP thought it was since it was marked as the accepted answer. Feel free to write another  answer yourself if you have another opinion.
RitterKnight
CC BY-SA 3.0
2016-02-24T22:18:31.150Z
2016-02-24T22:28:34.070Z
2017-04-13T12:51:00.253Z
RitterKnight
<p>Behind the scenes, the Rich Text field converts those links to <a href="https://craftcms.com/docs/reference-tags" rel="nofollow">reference tags</a> so that when the Craft install moves between environments (and the URLs change) or, for example, the entry's slug changes, it will still maintain a proper link to the entry instead of breaking.  Currently it requires linked URLs in absolute format to do that.</p>

CC BY-SA 3.0
2018-03-11T14:59:30.753Z
my rich text fields don’t seem to be converting links to reference tags, so when moving between environments, all of my rich text field links break.  Is there a config setting for this? [my question](https://craftcms.stackexchange.com/questions/24150/redactor-entry-links-to-dev-server)
artmem
CC BY-SA 3.0
2016-02-24T18:00:55.210Z
2016-02-24T18:00:55.210Z
Brad Bell
<p>A coworker of mine asked me if I could make the links in Craft relative.</p>

<p>Which is not a big deal for navigation links,</p>

<p>relative url:</p>

<pre><code>{% set relativeUrl = entry.url|replace((siteUrl), '/') %}
</code></pre>

<p>but it gets trickier for links inside a Rich Text field.</p>

<p>Craft is set up to use absolute links, is there a reason behind that?</p>

CC BY-SA 3.0
2016-02-24T10:17:52.373Z
Not answering your question, just wanted to point out that you can also use `entry.uri` to get the relative url.
André Elvan
<url>
Does it make sense to use Craft with relative links?
# Does it make sense to use Craft with relative links?

(Asked by: username_0 on 2016-02-24)

A coworker of mine asked me if I could make the links in Craft relative.
Which is not a big deal for navigation links,
relative url:
{% set relativeUrl = entry.url|replace((siteUrl), '/') %}

but it gets trickier for links inside a Rich Text field.
Craft is set up to use absolute links, is there a reason behind that?

**Tags:** url

> **Comments:**
> **username_1**: Not answering your question, just wanted to point out that you can also use `entry.uri` to get the relative url.  

---

## 2 answers

### Answer by username_2 on 2016-02-24. Score: 3 | Accepted answer

I would question the need to have relative URLs to begin with.

As [Brad mentions](https://craftcms.stackexchange.com/a/13876/1016), Craft neatly solves the multi-environment problem for you.

If you come from an environment like WordPress where it makes absolute URLs for you and then you end up having to do a find-replace on the content when switching environments (since there's no "built-in" way to do it), I can see where your co-worker might think relative is the way to go. However, even WP has good reason to do so.

Back before content management systems, relative URLs were probably the way to go because they are easier to code by hand; if you used conventions like "../" your pages also worked locally. Now with systems like Craft and local testing servers, creating links within content is much more consistent.

Craft even has a find/replace tool in the CP if you want to make sure those staging/production URLs absolutely get switched over in the database as well.

Speaking of consistency, google wants you to be as efficient as possible. From an SEO perspective, this [moz post](https://moz.com/blog/relative-vs-absolute-urls-whiteboard-friday) goes over the pros and cons of relative vs absolute but a few points worth summarizing:

* **Scrapers** can be a big problem stealing your content. Absolute URLs make it a bit more difficult for the laziest of them.
* By using things like `rel="canonical"` and letting Craft spit out your main base URL consistently, you can help avoid **duplicate content** issues.

[Yoast](https://yoast.com/dev-blog/relative-urls-issues/) gives some thoughts on this as well but I'll leave you with one takeaway:

> The few minutes a developer might save by using relative URLs are offset by countless hours an SEO might be spending to solve the issues caused.

> **Comments:**
> **username_3**: so you don't answer the question, reject the premise and reason with an article that basically states "it's bad for seo if you do it wrong" and present that as an answer to the question you rejected.  
> **username_2**: @username_3: Sorry you feel this didn't answer the question but clearly the OP thought it was since it was marked as the accepted answer. Feel free to write another  answer yourself if you have another opinion.  

---

### Answer by username_4 on 2016-02-24. Score: 1

Behind the scenes, the Rich Text field converts those links to [reference tags](https://craftcms.com/docs/reference-tags) so that when the Craft install moves between environments (and the URLs change) or, for example, the entry's slug changes, it will still maintain a proper link to the entry instead of breaking. Currently it requires linked URLs in absolute format to do that.

> **Comments:**
> **username_5**: my rich text fields don’t seem to be converting links to reference tags, so when moving between environments, all of my rich text field links break.  Is there a config setting for this? [my question](https://craftcms.stackexchange.com/questions/24150/redactor-entry-links-to-dev-server)  

---

