'rewrite rule code is not working for deep pages

I write some rewrite rule to manipulate the first folder after domain address as a query string indicating the language.

<rule name="en">
<match url="^en/(.*?/)" />
<action type="Rewrite" url="./{R:1}/?lang=en" />
</rule>

The code above works for first step folders:

http://example.com/en/members 
Executes: 
http://example.com/members/?lang=en 

but not or second and deeper steps.

http://example.com/en/members/profile/ 
Executes: 
http://example.com/members/?lang=en 

and the second step folder (profile) is being ignored.



Solution 1:[1]

Your first rule shouldn't work either, because the parameter ^en/(.*?/) doesn't match en/members, but you can try this rule:

<rule name="en">
  <match url="^en/([^/]+)" />     
  <action type="Rewrite" url="http://example.com/{R:1}/?lang=en" />
</rule>

enter image description here

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1