The AI marketing platform and home of

The AI marketing platform and home of

Marketing reports, apps, and automations, handled. Meet Letaido.

Marketing reports, apps, and automations, handled. Meet Letaido.

The only AI marketing platform built on Ahrefs’ proprietary web index.

The only AI marketing platform built on Ahrefs’ proprietary web index.

The AI marketing platform we needed didn’t exist. So we built it.

Tim Soulo

Tim Soulo, CMO at Ahrefs

The AI marketing platform we needed didn’t exist. So we built it.

Tim Soulo

Tim Soulo, CMO at Ahrefs

Firehose

Track brand mentions and competitor updates in real time.

Firehose

Track brand mentions and competitor updates in real time.

Relative URL

What is a Relative URL?

A relative URL is a Uniform Resource Locator (URL) that specifies the location of a target relative to the address of the page where it is situated.

Unlike absolute URLs, relative URLs do not contain the protocol (“http://” or “https://”) and the domain name (e.g., “ahrefs.com”).

For example, if the page
https://ahrefs.com/seo/glossary/relative-url/ (with a trailing slash, it’s important)
contained the following code:

<a href="best-practices">best practices</a>

the final destination of that link would be

https://ahrefs.com/seo/glossary/relative-url/best-practices

This example demonstrates the simplest use of a relative URL. To avoid errors associated with relative URLs, it’s important to be familiar with more advanced use cases.

Understanding a directory

Let’s look at the same example, but this time the page URL does not end with a trailing slash:

https://ahrefs.com/seo/glossary/relative-url

The same code on it

<a href="best-practices">best practices</a>

would now lead to

https://ahrefs.com/seo/glossary/best-practices

Why?

While there’s no difference for users, a URL with a trailing slash is technically a directory, whereas one without it is considered a file within the /glossary/ folder (directory). In this case, a relative URL is relative to the current directory.

There’s another format for a current directory-relative URL:

"./" before the link.

So these two links will lead to the same destination:

<a href="best-practices">best practices</a>
<a href="./best-practices">best practices</a>

Root-relative path

If the relative URL has a leading slash, it means that is relative to the root domain, ignoring all folder and subfolders.

Back to our example:

<a href="/best-practices">best practices</a>

This code on this page would create a link to

https://ahrefs.com/best-practices

One level up

The "../" prefix of a relative link makes it relative to the directory one level up from the current one.

The current directory for the URL https://ahrefs.com/seo/glossary/relative-url (without a trailing slash) is /glossary/.

So the following code

<a href="../best-practices">best practices</a>

will create a link to

https://ahrefs.com/seo/best-practices

Relative vs absolute URLs for SEO

In terms of SEO, there’s no difference between relative and absolute URLs in the links on pages.

However, it is recommended (but not prohibited) to use absolute URLs in rel=“canonical” and “hreflang” tags to minimize the potential for errors and confusion.

Starter

See what people search and spy on competitors.

Learn more ↗
27
/mo
Get started

Ahrefs Free

Get Ahrefs data on your site and fix what matters.

Learn more ↗