TransWikia.com

IIS rewrite language based rule and default language

Server Fault Asked on November 4, 2021

I want to create an IIS rewrite rule that is based on the users browser language, but only for a specific set of languages.

Our website is available in English (en), French (fr), and Dutch (nl).
I can create this rewrite rule:

<rule name="Redirect short url to long url: NEW SYNTAX 2017-11-01" stopProcessing="true">
    <match url="^([_0-9a-z-]+)$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="mydomain.be$" />
        <add input="{HTTP_ACCEPT_LANGUAGE}" pattern="^(en|fr|nl)?" />
    </conditions>
    <action type="Redirect" url="https://www.myotherdomain.be/{C:1}/projects/{R:1}?type=shorturl" appendQueryString="false" redirectType="Found" />
</rule>

This works fine when I configure my browser in one of the three specified languages (en/nl/fr).
Eg URL http://mydomain.be/test will redirect to https://www.myotherdomain.be/nl/projects/test?type=shorturl (when my browser is configured in Dutch).

But when I configure my browser e.g. to “ru” then then the same url will redirect to https://www.myotherdomain.be//projects/test?type=shorturl

For any other languages I want to default the long URL to /en/ instead of //
Is there any way to do this using IIS rewrite rules ?

Thanks in advance for any guidance!

One Answer

For info: I solved my issue by adding a catch all rewrite rule, that redirects all request to a single .aspx page. In this .aspx page I can handle the proper redirect logic with C# in the backend code.

Answered by Baz on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP