Interlink Hyperlink Modifier
The Interlink Hyperlink Modifier allows websites hosted on multiple top‑level domains (TLDs) to automatically rewrite hyperlinks so they always point to the correct domain. This is ideal for multi‑network environments such as .ca, .com, .us, .cjdns, .ygg, and .akn.
How It Works
Interlink detects the visitor’s current hostname, extracts the domain and TLD, and rewrites any
hyperlink marked with the interlink class.
This ensures links always point to the correct version of your site — no matter which TLD the
visitor is using.
document.addEventListener("DOMContentLoaded", () => {
const host = window.location.hostname;
const parts = host.split(".");
const detectedTld = parts.pop();
const domain = parts.join(".");
document.querySelectorAll(".interlink").forEach(a => {
const sub = a.dataset.sub;
const port = a.dataset.port;
const path = a.dataset.path;
const overrideTld = a.dataset.tld;
const tld = overrideTld || detectedTld;
let url = `http://${sub}.${domain}.${tld}`;
if (port) {
url += `:${port}`;
}
if (path) {
url += `/${path.replace(/^\/+/, "")}`;
}
a.href = `${url}/`;
});
});
Using Interlink
Option 1 — External JavaScript File
Add this to your page’s <head>:
<script src="/js/interlink.js"></script>
Option 2 — Inline Script
Place the script directly inside your <head>:
<script>
// Interlink code goes here
</script>
Inline scripts must be placed in the head so the DOMContentLoaded handler runs correctly.
Attributes
Interlink uses HTML data-* attributes to control link rewriting.
| Attribute | Description | Example |
|---|---|---|
data-sub |
Subdomain to link to. | data-sub="www" |
data-port |
Optional port number for non‑HTTP services. | data-port="46631" |
data-path |
Optional folder or file path inside the subdomain. | data-path="downloads/game.zip" |
data-tld |
Optional override to force a specific TLD. | data-tld="com" |
Examples
- Sonic3000 at The Furry Collective
- Hedgewars Server
- Download Classic Games Archive
- Force .com version of Blog (URL does not exist, so... it should return 404 or a registrar landing page)