Can I route based on the browser's language preference?
Short answer
Yes, on an HTTP vService. For Turkish and English, the ready-made If the client prefers Turkish over English and If the client prefers English over Turkish conditions that come with the product are selected directly in the Conditional Backend Services block. For other languages, the Client Language Preference condition evaluates the Accept-Language header according to q-factor priority. To send the user to an address belonging to the language version, the Location Redirection action is used. Clients that do not send Accept-Language meet none of the language conditions and go to Default Backend Services.
Background
The browser reports the user's language preferences in the Accept-Language header with priority values (q-factor, 0–1); e.g. de-DE,de;q=0.9,en;q=0.8 says that German is preferred first and English after it. A language given q=0 is not accepted.
Problem: Language Versions on Different Servers
If the language versions of a multilingual site run on separate servers, the user needs to be sent to the correct server according to the language preferred in the browser. Searching for plain text in the header leads to a wrong decision: tr occurs in the en-US,tr;q=0.1 header, but the client's actual preference is English.
Solution: Three Methods
Method 1 and Method 2 send the request to different Backend Services; Method 3 does not select a server, it redirects the client to the address of the language version.
| Your situation | Suitable method |
|---|---|
| Only a Turkish / English distinction is needed | Method 1: Ready-made conditions |
| There are other languages too | Method 2: Client Language Preference condition |
I want to send the user to the address of the language version (e.g. /de/) | Method 3: Location redirection |
Method 1: Ready-Made Conditions (TR / EN) Recommended
- How it works Two ready-made conditions that come with the product determine, according to the q-factor, whether the client prefers Turkish or English more; the two exclude each other. The NOT forms (If the client does NOT prefer Turkish over English etc.) are also in the selection list.
- Where it is opened vService form → + Conditional backend services → Select Conditions
- Requirement The target servers being defined as Backend Services
- vService type HTTP
Step-by-Step Configuration
If the servers of the language versions are not yet defined in TR7 as Backend Services, they are added first; if they are defined, this step is skipped. With Load Balancer → Backend Services → Add, the Backend Service Name and Address are entered for each server and a Health Check profile is selected. Details: How is a Backend Service added; which information is required?
The Load Balancer → Load Balancer vService List steps are followed and the HTTP vService is opened.
The + Conditional backend services button in the header of the Default Backend Services table is clicked (Conditional Backend Services).
In the Select Conditions field of the block, If the client prefers Turkish over English is selected; in the Backend Service selector, the Backend Services of the Turkish version are selected. If the English version is not in Default Backend Services, a second block is added in the same way with If the client prefers English over Turkish.
The Save button is clicked.
Verification
Requests are sent with different Accept-Language values; the Backend Service that gave the response is also seen on the HTTP Logs screen (Viewing HTTP Logs).
curl -s -H "Accept-Language: tr-TR,tr;q=0.9,en;q=0.8" http://203.0.113.10/tr first → Turkish Backend Service · en first → the other block or Default Backend ServicesMethod 2: Client Language Preference Condition
- How it works The language in the Language field is compared with the languages in the Languages to Compare field; if it is ahead in the client's q-factor ordering, the condition is met. Languages given
q=0are eliminated; regional variants (en-US,en-GB) are included in the base language. - Where it is openedLoad Balancer → Conditions · vService form → + Conditional backend services
- Requirement The target servers being defined as Backend Services; only the request stage
- vService type HTTP
Step-by-Step Configuration
The Load Balancer → Conditions → Add steps are followed; the form is described in the Conditions · How to Add? section.
The Condition Name is entered and Criteria = Client Language Preference is selected. In the Language field, the language to be routed is selected (e.g. German (de)); since the default value is aa, the first item of the list, a language must always be selected. In the Languages to Compare field, the other languages the site offers are selected (e.g. English (en)). If this field is left empty, the condition asks only the question "does the client accept this language".
The Add button is clicked.
For each language the site offers, steps 1–3 are repeated with the same language set (e.g. English, comparison: German). If the conditions are not defined with the same set, they do not exclude each other.
Steps 2–5 of Method 1 are applied; a separate block is added for each language, and that language's condition is selected in the Select Conditions field of the block.
Verification
Two requests are sent, one that puts German first and one that puts English first.
curl -s -H "Accept-Language: de-DE,de;q=0.9,en;q=0.5" http://203.0.113.10/de first → German Backend Service · en first → English Backend ServiceMethod 3: Location Redirection
- How it works A request that matches the condition is redirected with a 3xx to the address of the language version (e.g.
https://www.example.com/de/); this is not a server selection, the client sends a new request to the new address. Details: How do I redirect a specific URL to another URL with a 301/302? - Where it is openedLoad Balancer → Actions · vService form → Details → Actions
- Requirement A condition (if Location redirection is saved without a condition, it never runs); the ready-made TR / EN conditions can also be selected
- vService type HTTP
Step-by-Step Configuration
For Turkish / English, the ready-made conditions are used; for other languages, a condition is created with steps 1–3 of Method 2.
The Load Balancer → Actions → Add steps are followed.
Action Type = Location redirection is selected; the address of the language version is entered in the Redirect Location field, the redirect code (e.g. 302) is selected in the Redirect Code field, and the language condition is selected in the Conditions field. To prevent a redirect loop, the NOT form of a Path condition that selects requests starting with the target path (e.g. /de/) is added to the same group with AND.
The Add button is clicked.
The Load Balancer → Load Balancer vService List steps are followed, the vService is opened and the Details button at the top of the form is clicked.
The created action is selected in the Actions field.
The Save button is clicked.
Verification
A request that puts German first is sent and the response headers are checked.
curl -sI -H "Accept-Language: de" http://203.0.113.10/HTTP/1.1 302 · Location: https://www.example.com/de/Common Mistakes
- Searching for plain text in
Accept-Language. Searching fortrwith the HTTP header condition also catches requests that prefer English, such asen-US,tr;q=0.1; Client Language Preference, which takes the q-factor into account, or the ready-made conditions are used. - Leaving Languages to compare empty and assuming a preference comparison is made. When it is empty, the condition only checks whether the language is accepted; an English browser that accepts German in second place also matches.
- Setting up the conditions with different language sets. The TR condition must be compared with EN, and the EN condition with TR; otherwise the same request can meet both conditions and the block order determines the result.
- Forgetting clients that do not send the header. Clients that do not send
Accept-Language(e.g. some bots, API clients) go to Default Backend Services; the default language version is placed in Default Backend Services. - Opening separate conditions for regional variants. Selecting
enalso coversen-USanden-GBrequests.
How it is done in the documentation
