I run YT to MP4, a free YouTube to MP4 converter. Until this week it had a sister site on a second domain. Two domains meant two sets of links to earn, two Search Console properties and two sites competing for the same searches, so we merged them into one.
The whole site is built by one Node script of about 350 lines. No framework, no CMS. It writes plain HTML files that nginx serves. That made the merge a build problem instead of a migration project, and the build ended up doing most of the SEO work for us. Here is how it works.
The setup
Every page is a plain object: path, title, description, content, and the language it belongs to. Translations point back to their English original with an of field:
{ path: "/es/youtube-a-mp4-1080p/", lang: "es", of: "/youtube-to-mp4-1080p/", title: "...", ... } The build loops over every page and writes dist/<path>/index.html. Today that is 92 pages across 10 languages: English, Spanish, Portuguese, French, Indonesian, Hindi, Turkish, German, Arabic and Vietnamese.
hreflang from one map
Getting hreflang right by hand across 10 languages is how sites end up with broken alternates. We never write it by hand. While building, every page is grouped under its English original:
const groups = {}; for (const p of pages) { const key = p.of || p.path; (groups[key] ||= {})[p.lang || "en"] = p.path; } Each page then prints one <link rel="alternate" hreflang> for every language in its group, plus x-default pointing at English. Because all pages in a group read from the same object, the alternates are always reciprocal. If the Spanish page points at the German one, the German page points back. Pages that exist in only one language get no alternates at all, which is correct.
The same group powers the language picker, so a visitor on the Turkish 1080p page who switches to French lands on the French 1080p page, not the French homepage.
The build refuses to ship mistakes
The build collects problems in an array and exits with an error if there are any. Nothing deploys until the list is empty. It checks:
- every internal link points at a page that exists
- no path is defined twice
- every translation points at an English page that exists
- titles are 30 to 60 characters and descriptions 120 to 158, so Google doesn't cut them off
- every redirect target exists
That last check is what made the merge safe.
Merging two domains
The old site had 71 URLs, counting translations. Each one needed a single 301 to the closest matching page on the new domain. Not a blanket redirect to the homepage: that throws away whatever each page had earned and Google treats it close to a 404.
We wrote one small map from old English paths to new ones:
const MOVED = { "/": "/", "/youtube-shorts-downloader/": "/youtube-shorts-to-mp4/", "/youtube-video-download-hd/": "/youtube-to-mp4-1080p/", "/download-youtube-video-iphone/": "/youtube-to-mp4-iphone/", // ... }; Translations follow automatically. For an old Spanish page, the build looks up where its English original moved, then finds the Spanish version of that destination in the hreflang groups. If no Spanish version exists, it falls back to the Spanish homepage, and only then to the English homepage. Every computed destination goes through the same "does this page exist" check, so a typo in the map fails the build instead of shipping a broken redirect.
The output is a plain nginx include, one exact-match rule per URL, with and without the trailing slash:
location = /youtube-video-download-hd/ { return 301 https://yt-to-mp4.net/youtube-to-mp4-1080p/; } location = /youtube-video-download-hd { return 301 https://yt-to-mp4.net/youtube-to-mp4-1080p/; } The root keeps its query string ($is_args$args), because people share links like /?url=... and those should still work after the move.
Three details that are easy to miss
Keep a sitemap on the old domain. It sounds backwards, but the old domain still serves a sitemap listing all 71 old URLs, with lastmod set to the day of the move. That tells Google to recrawl them soon, and every recrawl finds a 301. Without it, Google revisits old URLs on its own schedule, which can take weeks.
Kill the old service worker. Both sites were installable apps with a service worker. A service worker keeps running in returning visitors' browsers, and it could keep serving the old site from cache, so the redirects would never even be requested. The old domain now serves a sw.js that deletes its caches and unregisters itself:
self.addEventListener("install", () => self.skipWaiting()); self.addEventListener("activate", (e) => { e.waitUntil( caches.keys() .then((k) => Promise.all(k.map((x) => caches.delete(x)))) .then(() => self.registration.unregister()) ); }); Tell the search engines once, then only what changed. In Google Search Console we used the Change of Address tool on the old property, which is built for exactly this. For Bing and the other IndexNow engines, a small script compares the sitemap that was live before the deploy with the new one and pings only the URLs that were added, changed or removed. A deploy that changes one page sends one URL, not 92.
What we watch now
For the first weeks after a merge, Search Console shows the moved pages as "Page with redirect" on the new property until Google recrawls them. That is expected. We request indexing for the most important language homepages and tool pages, and let the sitemap handle the rest.
The takeaway: if your site is generated, make the generator responsible for redirects and hreflang, not a spreadsheet. A map of about a dozen entries produced 71 correct redirects, and the build made it impossible to deploy a broken one.
If you want to see the result, every page of YT to MP4 is the output of that one script.