Skip to content

Instantly share code, notes, and snippets.

@dawoe
Created August 22, 2018 10:36
Show Gist options
  • Save dawoe/7bf4ef7e60fe3fdbf65f1f35c712d4bc to your computer and use it in GitHub Desktop.
Save dawoe/7bf4ef7e60fe3fdbf65f1f35c712d4bc to your computer and use it in GitHub Desktop.
Redirect based on browser language
<rule name="RedirectToDutchHomepage" enabled="true" stopProcessing="true">
<match url="^$"></match>
<conditions>
<add input="{HTTP_ACCEPT_LANGUAGE}" pattern="^nl"></add>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/nl/"></action>
</rule>
<rule name="RedirectToFrenchHomepage" enabled="true" stopProcessing="true">
<match url="^$"></match>
<conditions>
<add input="{HTTP_ACCEPT_LANGUAGE}" pattern="^fr"></add>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/fr/"></action>
</rule>
<rule name="RedirectToGermanHomepage" enabled="true" stopProcessing="true">
<match url="^$"></match>
<conditions>
<add input="{HTTP_ACCEPT_LANGUAGE}" pattern="^de"></add>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/de/"></action>
</rule>
<rule name="RedirectToEnglishHomepage" enabled="true" stopProcessing="true">
<match url="^$"></match>
<action type="Redirect" url="https://{HTTP_HOST}/en/"></action>
</rule>
@dawoe
Copy link
Author

dawoe commented Aug 22, 2018

This will redirect the user based on browser language.
If nl, fr or de is detected in the browser language it will be redirected to the homepage ofr that language
If not the user will be redirected to the english homepage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment