Antonio Bakula
Antonio Bakula

Reputation: 20693

IIS URL Rewrite rule - Default document for subdirectories

I would like create URL rewrite rule that will set default document for my virtual folders. eg. someting like this

www.domain.com/en/ -> www.domain.com/en/index.aspx
www.domain.com/hr/ -> www.domain.com/hr/index.aspx
www.domain.com/de/ -> www.domain.com/de/index.aspx

directories en, hr, de doesn't really exists on web server they are just markers for languange used in site used by home grown http module that will rewrite path with query params.

Quick solution was define rule for every single lang, something like this :

<rewrite>
    <rewriteMaps>
        <rewriteMap name="Langs">
            <add key="/en" value="/en/index.aspx" />
            <add key="/hr" value="/hr/index.aspx" />
            <add key="/de" value="/de/index.aspx" />
        </rewriteMap>
    </rewriteMaps>
<rules>

But I would really like solution that would not require changes in web.config and adding rewrite rule for every languange used on particular site.

Thanks !

Upvotes: 0

Views: 2438

Answers (1)

Matthew Abbott
Matthew Abbott

Reputation: 61599

<rule name="Lang-Redirect">
    <match url="^(\w{2})\/?$" />
    <action type="Rewrite" url="{R:1}/index.aspx" />
</rule>

That should allow you to capture the language tag from the request and rewrite it to your custom http handler.

Upvotes: 2

Related Questions