Custom language redirections.

Hello,

We are implementing a multilingual setup where the website should redirect users to the correct language version based on either:

Their previously selected language (stored in a cookie), or

Their browser language / location on first visit.

Currently, the redirect happens after the page starts loading.
Using a script.
The redirect to occur before the page loads at all, so the user immediately lands on the correct language version without seeing the original page first.

Question:
Is it technically possible to trigger the language-based redirect before the page begins loading (server-side), instead of performing the redirect client-side after the page has already started rendering?
If so, what would be the recommended approach or hooks to implement this?
(The pages are not all translated some pages are not avaible for some countries so all languages have different kind of pages.)

Here is a way you could attempt using react and hubl:

Use HubL backed by a HubDB table to output a “language routing config” into every page: supported languages, language-specific URLs, and which pages exist in which languages. Then, add a very small script high in the global head that reads this config plus the language cookie / browser language and immediately redirects to the correct URL before your React app initializes. Your React app then handles language switching inside the experience and updates the preferred-language cookie whenever the user changes language.
Let me know if this helps, or if you have any other questions!
Moderator note: While this solution may not address the original poster’s specific situation, it could be helpful for other community members facing similar challenges.


:check_mark: Was I able to help answer your question? Help the community by marking it as a solution.

Brandon Woodruff
Senior Software Developer @ PearagonStill have questions? Reach out at brandon@pearagon.com

Thanks @BrandonWoodruff :raising_hands:

Thanks for your reply,
I had a look into this and came to the conclusion that maybe cloudflare redirecting would be a better alternative. Do you have any experience with cloudflare and know if I can get the page link using the hubspot api to always redirect it to a existing page that is inside the language group?

Hi @Bent1 and thanks for getting back to us!
You can use the CMS Pages API to retrieve language group information and build your own redirect logic.

The API provides these properties for multi-language pages:

- translatedFromId: ID of the primary language page
- language: ISO 639 language code
- translations: map of language codes to variant pages
You could fetch this data via API and implement Cloudflare redirect rules based on it.
However, HubSpot doesn’t automatically redirect users by GeoIP, you’d need to handle that logic yourself.
Here are the related resources:
- CMS API | Pages
- Multi-language Content
- CMS API | URL redirects
I hope it helps!
Have a wonderful weekend!
Bérangère
This post was created with the assistance of AI tools.