Building a Bilingual English–Persian Next.js Site: hreflang, RTL and What Stays in One Language
A working architecture for an English-first site with a Persian (RTL) tree: an allow-list of real translations, reciprocal hreflang only where both pages exist, lang and dir on every document, stable shared identity data, and a proper Persian 404.


Text equivalent. Bilingual routing Teaching diagram • Paired pages and real translations Real Persian pages Translation allow-list hreflang alternates Only real translated pairs Sitemap twins Real /fa entries only Language switcher Offer the available twin Persian URL resolution Missing translation > 404 Architecture choice • expected behaviour; integrated local-build checks still required
Adding Persian to an English site looks like a translation job. Most of the work is actually deciding things: which pages really exist in both languages, how each page points to its counterpart, how the document switches direction, which data stays in one language, and what a Persian visitor sees when a page has no translation.
This article goes through those decisions as they appear in this site's source (pinned commit, see the scope note). English is the primary language, with a Persian tree under /fa. For each choice I note whether it's a Google requirement, a web-standards recommendation, or our own architecture choice. Those are three different kinds of reason, and teams often treat the third as if it were the first.
Scope. This describes the English–Persian setup of shahabbuilds.com as it exists in the site's source at a pinned commit; counts and behaviour must be re-confirmed on the integrated production build before publication. It's an architecture walkthrough, not a promise about search visibility. hreflang helps Google show the right language version. It doesn't guarantee ranking improvements.
1. Decide which pages get a Persian twin before you write any routing
The most important file in a bilingual build is a list: the pages that have a real Persian version.
On this site that list is an explicit allow-list of paths. At the time of writing it holds the seven hub pages, the nine case studies and the six original blog posts. Every other bilingual behaviour reads from that one list:
- whether a page emits a
fahreflang alternate - whether the sitemap includes a
/fatwin - whether the language switcher offers "فارسی" on that page
- which
/fa/...URLs resolve to a page and which return a Persian 404
Why an allow-list rather than "mirror everything": Google's guidance says localized versions "are only considered duplicates if the main content of the page remains untranslated". Generating a Persian route does not create a usable translation. We add it only when its main content has a reviewed Persian translation or adaptation. An allow-list makes "this page exists in Persian" a decision someone made and can review, not a side effect of a route pattern.
Tradeoff: someone has to maintain the list. A new English article doesn't get a Persian URL until a real translation is written and added, and that's intentional. The risk is drift, where the list says a translation exists and the route doesn't, or the reverse. Section 7 covers the build-time guard for that.
Decision aid: a page belongs on the allow-list only if you can answer yes to all three:
- The Persian main content is a real translation or adaptation, not boilerplate around English text.
- Someone will update the Persian version when the English one changes in a material way.
- A Persian-reading buyer would actually use this page. Hub, service and case pages usually qualify; a niche English-only technical post may not.
2. The URL model: unprefixed English, /fa for Persian
What Google asks for is narrow. It "recommends using different URLs for each language version of a page rather than using cookies or browser settings to adjust the content language on the page." Any of these meets that: subdirectories, subdomains or separate domains.
Our specific model is an architecture choice:
| Choice | What we do | Why | What it costs |
|---|---|---|---|
| English URLs | Unprefixed (/about, /blog/{slug}) | English is the primary audience; short, stable URLs | English and Persian aren't symmetrical in the code, so the Persian side needs explicit handling |
| Persian URLs | Under /fa (/fa/about) | Same host, simple to deploy, obvious to users | Google lists "separation of sites harder" as a con of subdirectories |
Legacy /en/... | Redirects to the unprefixed path | One URL per English page | Another rule to keep correct |
x-default | Points to the English page | Identifies our English URL as the fallback alternate for unmatched language preferences | Google says x-default "was designed for language selector pages and so it will work best with those". Pointing it at English is our choice, not their default |
| Language detection | No automatic redirect by browser language; a visible switcher link instead | Google: "Avoid automatically redirecting users from one language version of a site to a different language version" | A Persian speaker who lands on English has to click once |
The Next.js internationalization guide shows routing by "sub-path (/fr/products) or domain (my-site.fr/products)" and an example that redirects visitors based on the Accept-Language header. That example is an application routing option; for these public pages we prefer stable locale URLs and explicit switching rather than forcing a guessed language. Google notes that its crawler "sends HTTP requests without setting Accept-Language in the request header", and it advises against redirecting by a guessed language. We kept language selection explicit.
Implementation note for the App Router: the Next.js guide nests everything under app/[lang]. This site uses two route groups instead, an English group and a Persian group under /fa, and each one renders its own <html> element with its own language and direction. Route groups don't add a URL segment, so English stays unprefixed. If you give each language its own root layout, the Next.js docs warn that navigating "between routes that use different root layouts" triggers a full page reload. For a language switch that's acceptable. For links inside one language, keep them inside the same group.
3. Reciprocal hreflang, only where both versions exist
This is the part where Google's documentation is strict, and every claim below comes from it:
- "Each language version must list itself as well as all other language versions."
- "If two pages don't both point to each other, the tags will be ignored."
- Alternate URLs "must be fully-qualified, including the transport method".
- Language codes are ISO 639-1. Persian is
fa. A region (fa-IR) is optional. A country code on its own isn't valid.
For a page on the allow-list, both the English and the Persian document carry the same set:
<link rel="alternate" hreflang="en" href="https://shahabbuilds.com/about" />
<link rel="alternate" hreflang="fa" href="https://shahabbuilds.com/fa/about" />
<link rel="alternate" hreflang="x-default" href="https://shahabbuilds.com/about" />On an English-only page, the set shrinks to the page itself: en plus x-default, both pointing to the English URL. It never points to a /fa URL that doesn't exist. A hreflang link to a 404, a redirect or a non-equivalent page is an annotation Google can't pair, and it tells your own team something false.
Two related rules:
- Canonical stays in-language for these pages. Because these are genuinely translated pages, each version canonicalizes to itself, so the Persian page's canonical is its
/faURL. That's our reading of how the two signals fit together for translated pairs, not a rule for every regional or duplicate scenario. Google's multilingual guidance reservesrel="canonical"for "similar or duplicate content on different URLs in the same language". - hreflang doesn't set the language Google detects. Google says it doesn't "use
hreflangor the HTMLlangattribute to detect the language of a page". It uses the visible content, and it recommends "a single language for content and navigation on each page" and "avoiding side-by-side translations". A Persian page with an English body is still an English page as far as language detection goes.
Google accepts hreflang in HTML, HTTP headers or the sitemap, and says the three are equivalent. Pick one source of truth. This site emits hreflang from the same metadata builder that writes the canonical, so one function decides both from the allow-list.
4. lang and dir on the document; dir="auto" where users type
Direction is a web-standards matter (W3C), separate from search:
- "If the overall document direction is right-to-left, add
dir="rtl"to thehtmltag." - Declare the language as well, but "do not make the mistake of assuming that language declarations indicate directionality, or vice versa".
lang="fa"doesn't make a page RTL. You need both attributes. - "Never use CSS to apply the base direction." Use logical properties instead (
margin-inline-start,text-align: start) so one stylesheet mirrors itself.
In the site's source, the English documents render lang="en" dir="ltr" and the Persian documents render lang="fa" dir="rtl". The Persian tree also loads its own RTL stylesheet and a Persian web font.
User input needs separate handling, because you can't know its direction in advance. A Persian visitor types an English company name, or an English visitor pastes a Persian address. W3C's guidance: "Set the dir attribute to auto on forms and inserted text in order to automatically detect the direction of content supplied at run-time."
The snippet below is a recommended pattern, not markup quoted from this site:
<label for="company">Company</label>
<input id="company" name="company" dir="auto" dirname="company.dir" />dirname sends the detected direction with the form so the text can be displayed correctly later, in a CRM or an email. The same dir="auto" applies to any block that shows user- or database-supplied text, such as testimonials, names or search results.
Edge cases worth testing in Persian layouts:
- Mixed runs. An English product name or a number inside a Persian sentence can push punctuation to the wrong side. W3C covers the inline fixes (such as
<bdi>) in its separate inline-bidi article. - Titles that start with Latin text. Browsers pick the direction of a tab title from its first strong character, so a Persian page title that starts with "SEO" or "AI" can display in the wrong order. W3C suggests a leading right-to-left mark as a workaround.
- Lines with no letters. Phone numbers and order IDs (
123-456) align differently across browsers in RTL text areas. dir="auto"guesses from the first strong character. A Persian message that opens with an English word will be laid out LTR. That's usually acceptable for input. For long mixed content, set direction per paragraph.
5. What stays in one language: shared identity data
Structured data has two layers, and we treat them differently. This is an architecture choice. It isn't a Google requirement, and no structured data guarantees a rich result.
| Layer | Examples | Language on Persian pages | Why |
|---|---|---|---|
| Identity entities | WebSite, Person, Organization, the professional service and its offer catalog | English copy and English URLs, with the same @id on both locales (this site's source) | One entity, one stable identifier across language versions |
| Page nodes | WebPage name, BreadcrumbList, BlogPosting | Persian on Persian pages | These describe the visible page, so they follow its language |
The WebSite node lists both languages (inLanguage: ["en", "fa-IR"]). Service entries keep their English URLs, which are fragments of the single /services page, even inside a Persian graph. The Persian services page is a translation of that page, not a separate set of offers.
The same publisher can retain stable Person and Organization identifiers across language versions. Shared identity facts may remain consistent even when their names or descriptions are expressed in a different language. Page-specific claims, localized descriptions and service details must accurately represent the visible page; keeping an English shared entity is not permission to add unsupported facts. In this site's source, shared identity nodes use English while localized page nodes use Persian.
Tradeoff: if the Persian-speaking market is your main market, the balance changes. You may want the primary identity in Persian, with English as the translation.
6. Missing pages: a Persian 404, with noindex and no hreflang
Someone will request a Persian URL that doesn't exist: an old link, a guessed slug, or /fa/ in front of an English-only article. What happens next is a choice.
Our choice: any unknown /fa/... path gets the Persian not-found page with a real 404 status, an explicit noindex, and no hreflang alternates. Because it renders inside the Persian layout, it's still lang="fa" dir="rtl". The visitor sees an RTL page in their language, not an English error.
Why not redirect /fa/x to the English /x? It feels friendlier. But it also hides missing translations from your own reporting, sends Persian readers to a different-language page without telling them, and blurs which URLs actually exist in Persian. A clear 404 is more honest. Make sure the 404 template gives the reader a way forward, such as links to the Persian home page and, where one exists, the English version.
The page-pair matrix
This table is the specification we check against. The values are the expected behaviour from the site's source. HTTP status codes in particular should be confirmed on a production build, not in development.
| Request | Status | Canonical | hreflang emitted | <html> | In sitemap | Language switcher |
|---|---|---|---|---|---|---|
/about (translated pair, English) | 200 | /about | en → /about, fa → /fa/about, x-default → /about | lang="en" dir="ltr" | Yes | Offers Persian |
/fa/about (translated pair, Persian) | 200 | /fa/about | Same three-link set as above | lang="fa" dir="rtl" | Yes | Offers English |
/blog/{english-only-post} | 200 | Itself | en + x-default → itself; no fa | lang="en" dir="ltr" | English only | No Persian option |
/fa/blog/{english-only-post} | 404 | None | None | lang="fa" dir="rtl" | No | n/a |
/fa/{anything-unknown} | 404 | None | None | lang="fa" dir="rtl", noindex | No | n/a |
/{anything-unknown} (English) | 404 | None | None | lang="en" dir="ltr", noindex (expected; confirm the mechanism on the integrated build) | No | n/a |
/en/about (legacy prefix) | Redirect → /about | n/a | n/a | n/a | No | n/a |
/fa/blog/rss.xml (Persian feed) | 200 (feed) | n/a | Deliberately excluded | n/a | Deliberately excluded | n/a |
7. Checks before a language launch, or before adding a page
Run these against a production build, by viewing the rendered <head> and checking status codes. Don't rely on the code you meant to write.
Allow-list and routing
- Every path on the allow-list has a real Persian page, and every Persian page is on the list. This site's build fails if its lists of Persian case and post slugs drift from the Persian routes it generates. That kind of guard is worth adding to any bilingual build.
- A new English-only page doesn't produce a
/faURL, afaalternate, a Persian sitemap row or a switcher option. - Unknown
/fapaths return 404 withnoindexand a Persian layout.
hreflang and canonical
- Each translated pair lists itself and its counterpart, with fully qualified
https://URLs, and both pages carry the identical set. - No alternate points to a redirect, a 404 or a
noindexpage. - Each language version canonicalizes to itself.
- One method is the source of truth (HTML, headers or sitemap). If you emit more than one, they agree.
Direction and language
<html>carries the correctlanganddiron every template, error pages included.- Forms and user-supplied text use
dir="auto"; mixed-direction strings render correctly. - Layout uses logical CSS properties; nothing in the Persian tree is hard-coded
left/rightunless it's meant to stay put. - Each page's visible content, navigation included, is in one language.
Structured data
- Identity entities keep one
@idacross locales; page-level nodes match the visible language of the page. - Page-specific structured-data claims match the visible page; shared identity nodes add no unsupported facts (check actual properties against visible content in the runtime gate).
The metadata builder that emits these hreflang links also writes canonicals, Open Graph and sitemap entries. How to specify and test that output is in an SEO implementation contract with a test matrix.
Where this pattern applies
This architecture suits an English-first company that also sells to Persian-speaking customers. Persian gets a real but smaller set of pages, rather than an exact mirror. Another bilingual Persian/English build we delivered, the Asoomed holding-company site, had similar concerns: server-rendered pages in two languages, with technical SEO aimed at English visibility. That's a different codebase, so don't read its routing as identical to what's described here.
For general crawlability and on-page basics that apply to either language, see Website SEO basics that drive results.
Planning an English + Persian product or company site? Bring your page list and I'll help you decide which pages need a real Persian twin, and how routing, hreflang and RTL should work, before anything is built. This sits under SaaS & Product Engineering, and you can start the conversation here.
Sources
- Google Search Central, Tell Google about localized versions of your page: https://developers.google.com/search/docs/specialty/international/localized-versions
- Google Search Central, Managing multi-regional and multilingual sites: https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites
- Google Search Central, General structured data guidelines: https://developers.google.com/search/docs/appearance/structured-data/sd-policies
- W3C Internationalization, Structural markup and right-to-left text in HTML: https://www.w3.org/International/questions/qa-html-dir
- Next.js, Internationalization guide: https://nextjs.org/docs/app/guides/internationalization
- Next.js, Route groups (multiple root layouts caveat): https://nextjs.org/docs/app/api-reference/file-conventions/route-groups
What could this change for you?
Tell me what you’re building — I’ll tell you honestly where I’d start.
Start a project with me