Small SEO Tools

How to Check Relative Links Before Moving an HTML Page

A link can keep exactly the same HTML and open a different document after its page moves. Relative addresses depend on a base URL. Before relocating an HTML page, check where each link resolves from the new address and what the destination actually returns.

This example follows a text guide through a folder change. The example.com addresses are fictional; the browser tests described below used isolated local HTTP pages.

Record the destination before moving the page

Suppose a page at https://example.com/guides/start.html contains:

<!-- download card -->
<a id="download" href="../downloads/guide.txt">Download the guide</a>

The intended file is https://example.com/downloads/guide.txt. With no explicit base element, the parent-directory reference goes up from /guides/ to the site root, then into /downloads/.

Move the page to https://example.com/archive/guides/start.html, and that same reference goes up to /archive/ instead. Its resolved destination becomes https://example.com/archive/downloads/guide.txt. MDN explains the distinction between directory-relative and root-relative references. Resolution uses the base address; it does not search for a file with the right name.

Write down the intended document and edition before editing. A matching final filename is insufficient when several folders contain a guide.txt.

Check the saved href separately from its resolved address

If you minify the source, retain an editable copy. Paste the complete fragment above into the HTML Minifier. Keep Remove comments (keep conditional) checked, untick Remove whitespace between tags, and leave quote removal and boolean attribute collapsing unchecked. Select Minify HTML.

The current output for this example is:

<a id="download" href="../downloads/guide.txt">Download the guide</a>

The comment disappears, but the address remains relative. The minifier does not decide where the page will be hosted or check its destinations.

In the browser console on the actual saved page, inspect these three values:

document.baseURI
document.querySelector("#download").getAttribute("href")
document.querySelector("#download").href

The attribute is the stored reference; the anchor’s href property gives its resolved address. Check document.baseURI rather than assuming it equals the address bar: an existing <base href="..."> can change it. MDN’s base element reference describes that document-wide behavior. Adding a base element as a quick repair can affect other links and resources, so review the whole page before considering that approach.

Test the returned document, even when the response is 200

We ran the unchanged current minifier code locally in Chrome, then followed the resulting anchor in four local HTML documents. The test server deliberately returned a different text document at the archive path:

Page and link setup Requested path Observed response
Original page; ../downloads/guide.txt /downloads/guide.txt 200; intended Workshop guide, Spring edition
Moved page; unchanged relative link /archive/downloads/guide.txt 200; unrelated Archive index
Moved page; /downloads/guide.txt /downloads/guide.txt 200; intended Workshop guide, Spring edition
Moved page; original link and explicit /guides/ base /downloads/guide.txt 200; intended Workshop guide, Spring edition

Every request succeeded at the HTTP level, but the unchanged link on the moved page retrieved the wrong content. These are controlled fixture results, not measurements of a production site. On your page, follow each important link and confirm its final URL, file contents and edition, including any redirect destination.

Choose a path that matches the intended move

For this specific move, the page and intended file stay on the same origin, and the file remains at /downloads/guide.txt. A root-relative reference preserves that location:

<a id="download" href="/downloads/guide.txt">Download the guide</a>

If the file moves too, choose its new path instead. If it belongs on another origin, use its verified full address. Relative links are useful; the requirement is that their resolved destinations match your plan. Google’s link guidance includes relative addresses in anchors with href. Converting every link to an absolute URL is not a prerequisite for crawlable navigation.

After saving, repeat the checks from the new page address. Review images and stylesheets that also use relative paths. If the original control is a script-driven navigation button, the crawlable navigation link guide covers that separate markup repair. If the old public page address needs a redirect, use the redirect verification procedure as a separate step; correcting a link inside the moved page does not redirect visitors from its old address.