If you are building server-rendered Angular or Next.js apps, check out next-generationFirebase App Hosting,a full-stack solution for modern web frameworks.
Stay organized with collectionsSave and categorize content based on your preferences.
Use internationalization rewrites ("i18n rewrites") to serve different content
depending on a user's country or preferred language. Here are some example
configurations that you could set up:
Serve the same French content toallusers who prefer French (regardless
of country).Example: a homepage with French text
Serve Standard French content to users who prefer French, but forCanadianusers who prefer French, serve Canadian French content
instead.Example: a homepage with Standard French phrasing versus a homepage with
Canadian French phrasing
Serve the same content toallCanadian users (regardless of their
language preference).Example: a homepage with your site's "default" language but with a
Canada-specific feature (like a holiday theme)
Serve Canadian French content to Canadian users who prefer French.Example: a homepage with Canadian French phrasing and a Canada-specific
feature (like a holiday theme)
Firebase Hostingdetermines a user's country from their IP address and a
user's language preferences from theAccept-Languagerequest header (usuallyset automatically by their web browser).
Set up i18n rewrites
To set up i18n rewrites for yourHostingsite, you need to create an "i18n
content" directory for all your localized content, then add thei18nattribute
to yourfirebase.jsonfile to point to your new "i18n content" directory.
Here are the detailed steps:
Within your local app directory'spublicfolder, make a separate directory
for your "i18n content", then create subfolders for each language and
country combination supported by your site.
In each subfolder, add the content specific for that combination, like
holiday-themed homepages or language-specific 404 pages.
Here's an example "i18n content" directory calledlocalized-files:
View the matching requests for each subfolder's content
public///matchesrequeststhataren't specified by your "i18n content" subfolders// example: display your homepage in the "default" language for your site with no country-specific featuresindex.html// your site'sdefaulthomepage404.html//yoursite's custom 404 pagelocalized-files/// matches requests from Canada with any language preference// example: display your homepage in the "default" language for your site with a Canada-specific featureALL_ca/index.html// matches requests from any country with a language preference of `es` or `es-foo`// example: display your homepage in Spanish with no country-specific featureses_ALL/index.html404.html // your site'scustom404pageinSpanish//matchesrequestsfromanycountrywithalanguagepreferenceof`fr`or`fr-foo`//example:displayyourhomepageinStandardFrenchwithnocountry-specificfeaturesfr/index.html404.html//yoursite's custom 404 page in French// matches requests from Canada with a language preference of `fr` or `fr-foo`// example: display your homepage in Canadian French and/or with a Canada-specific featurefr_ca/index.html
Thelocalized-files/directory contains separate subfolders for each
language and country combination supported by your site. The naming pattern
for each subfolder must follow either of these formats:
languageCode_countryCode: Contains content specific for users
who have that language preferenceandthat country code
languageCode: Contains content specific for users who have that
language preference, but the content isn't country-specific; basically
equivalent tolanguageCode_ALL
Refer to the subsectionCountry and language codesbelow
for more details about these codes. You can use the value ofALL(case-sensitive) to indicateanycountry (likees_ALL/) oranylanguage (likeALL_ca/).
The files in a subfolder don't need to have analogous files in thepublicdirectory or other subfolders. You can create content that is entirely
specific to a language and/or country.
Add thei18nattribute to yourfirebase.jsonfile and specify the
directory that contains your "i18n content". Continuing our example:
// firebase.json"hosting":{"public":"public","ignore":["firebase.json","**/.*","**/node_modules/**"],"i18n":{"root":"/localized-files"// directory that contains your "i18n content"}...}
The directory specified forrootmust be the name of the directory that
contains all your "i18n content" subfolders. If you placed all your
"i18n content" subfolders at the root of yourpublicdirectory, use/for the value ofroot. Leading and trailing slashes in therootvalue
are optional.
Deploy your "i18n content" and config to yourHostingsite.
When naming "i18n content" subfolders, you must use lowercase for both country
and language codes. You can use the value ofALL(case-sensitive) to indicateanycountry (likees_ALL/) oranylanguage (likeALL_ca/).
Hostingobtains the country code from the user's IP address. Country codes
are two-letterISO 3166-1 alpha-2 codes.
WhenHostingsearches for which "i18n content" to serve, it orders the
languages based on the quality values in theAccept-Languageheader.
Hostingdrops any regional and country subtags in theAccept-Languageheader, so the language code in a "i18n content" subfolder name cannot
contain these subtags. For example, you can't usees-419ores-USas a
language code in a subfolder name, but you can usees.
If you want to serve specific regional or country content, you can create
subfolders that contain the specific language-country content you want to
support.
View examples to support specific regional or country content
Serve Spanish content applicable for Spain versusanyother country (mimic the behavior ofes-419)
In this example, a request from Spain with the language preference ofes,es-es, or evenes-419would receive content from thees_es/subfolder becauseHostingtreats all those language codes ases.
A request from the United States, Mexico, or any other country with the
language preference ofes-419would receive content from thees_ALL/subfolder becauseHostingtreatses-419ases.
public///matchesrequeststhataren't specified by your "i18n content" subfoldersindex.html// the site'sdefaulthomepagelocalized-files///matchesrequestsfromSpainwithalanguagepreferenceof`es`or`es-foo`es_es/index.html//matchesrequestsfromanyothercountrywithalanguagepreferenceof`es`or`es-foo`es_ALL/index.html
In this example, a request from Mexico with the language preference ofes-419would receive content from thees_mx/subfolder becauseHostingtreats the language codees-419ases.
However, a request from the United States with the language preference ofes-419would receive content from thees_ALL/subfolder becauseHostingtreatses-419asesandthere's noes_us/subfolder.
public///matchesrequeststhataren't specified by your "i18n content" subfoldersindex.html// the site'sdefaulthomepagelocalized-files///matchesrequestsfromArgentinawithalanguagepreferenceof`es`or`es-foo`(mimicsbehaviorof`es-ar`headertag)es_ar/index.html//matchesrequestsfromSpainwithalanguagepreferenceof`es`or`es-foo`(mimicsbehaviorof`es-es`headertag)es_es/index.html//matchesrequestsfromMexicowithalanguagepreferenceof`es`or`es-foo`(mimicsbehaviorof`es-mx`headertag)es_mx/index.html//matchesrequestsfromanyothercountrywithalanguagepreferenceof`es`or`es-foo`(mimicsbehaviorof`es-419`headertag)es_ALL/index.html
Priority order for "i18n content"
If you set up i18n rewrites,Hostingserves content based on the following
priority order:
Reserved namespaces that begin with a/__/*path segment
Language code + Country code (for example, content fromfr_ca/)The order follows the quality values for each language in the request'sAccept-Languageheader.
Country code only (for example, content fromALL_ca/)
Language code only (for example, content fromfr/ores_ALL/) The order follows the quality values for each language in the request'sAccept-Languageheader.
"Default" exact-match static content This is content that's outside the "i18n content" directory, like at the
root of thepublicdirectory.
Language codes:fr,en(French, then English) The language codes are ordered based on quality values in theAccept-Languageheader.
Country code:ca(Canada)
According to the exact-match priority order and the quality values for the
language preferences,Hostingwill search the directories for a requested
page in the following order.
public/localized-files/fr_ca/
public/localized-files/en_ca/
public/localized-files/ALL_ca/
public/localized-files/fr_ALL/
public/localized-files/fr/
public/localized-files/en_ALL/
public/localized-files/en/
public/
404 handling
Which page will be served to the user?
Requested page:index.html
Answer
index.htmlfrom thefr_ca/subfolder
SinceHostingsearches thefr_ca/subfolder first, it will find the
exact-match forindex.htmlin that subfolder.
Requested page:awesome-page.html
Answer
404.htmlfrom thefr/subfolder
Hostingfirst searches the entire directory (including all the
"i18n content" subfolders and root directory) in priority order for an
exact-match, but there's not an exact-match forawesome-page.html.
So,Hostingwill start its 404 handling, which follows the same i18n
priority order as exact-match searches. Thefr/subfolder is the first
subfolder searched that contains a 404 page.
Note the following about this search-and-serve of the "i18n content" directory:
Thelocalized-files/directory doesn't actually containen_ca/,en_ALL/, oren/subfolders, soHostingwill just skip down the
priority list until it finds a matching subfolder for the request's
language-country combination.
Even though thelocalized-files/directory contains anes_ALL/subfolder, the examplerequestabove doesn't include anesores-foolanguage code, soHostingwill not search for "i18n content" that
matcheses.
Subfolders calledfr/andfr_ALL/are equivalent from the perspective of
a user's country and language preferences. However, if both subfolders
exist,Hostingwill servefr_ALL/content beforefr/content.
Override language and country codes with cookies
You can change what content is served by using cookies to override the country
and language headers.
Here are some ways you can use cookie overrides:
Test a feature with different language/country combinations to check which
content is served.
Enable your users to change the content that they see. For example, you can
implement a language picker, then set the user'sfirebase-language-overridecookie accordingly.
To configure cookie overrides, set cookies with both or either of these names:firebase-country-overrideandfirebase-language-override. For example,
the following JavaScript code snippet overrides the country code to becaand
theAccept-Languageheader to befr,en:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[],[],null,[]]