Ali Sheikhpour
Ali Sheikhpour

Reputation: 11055

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.

Upvotes: 0

Views: 53

Answers (1)

samwu
samwu

Reputation: 5205

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

Upvotes: 1

Related Questions