Reputation: 19772
I want to rewirte my querystring for selected language.
I have this URL: www.example.com/?lang=en, and want it to be www.example.com/en
It should rewrite on all pages. So www.example.com/contact.aspx?lang=en would be www.example.com/en/contact.aspx
Is there a general rewrite rule for this?
Upvotes: 2
Views: 2034
Reputation: 19772
This one works.
<rule name="Rewrite Language">
<match url="([a-z]{2})(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:2}?lang={R:1}" />
</rule>
Upvotes: 2
Reputation: 1004
Please consider using the following:
<rewrite>
<rules>
<rule name="Rewrite Language">
<match url="/([a-z]{2})(.*)" />
<action type="Rewrite" url="{R:2}?lang={R:1}" />
</rule>
</rules>
</rewrite>
Upvotes: 0
Reputation: 10865
my syntax may be a little off but you could probably do something like this:
<rewrite>
<rules>
<rule name="Rewrite Language">
<match url="/([a-z]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="{R:2}?lang={R:1}" />
</rule>
</rules>
</rewrite>
Upvotes: 0