I have implemented URL Redirect rules on IIS using URL Rewrite 2.0 for my web application. I have multiple rules including Rewrite and Redirect action type. Here are the rules i created on IIS for my site:
RULE 1:
<rule name="SetServerVariables"><match url="^COMP/(.*)" /><conditions logicalGrouping="MatchAll" trackAllCaptures="false" /><serverVariables><set name="HTTP_X_ORIGINAL_COMMERCIAL_URI" value="{R:0}" /></serverVariables><action type="None" /></rule>
RULE 2:
<rule name="RemoveFromURL" enabled="true" stopProcessing="false"><match url="^COMP/SUB/(.*)/([/\-\.0-9a-z]*)" /><conditions logicalGrouping="MatchAll" trackAllCaptures="false" /><action type="Redirect" url="/SUB/{R:2}" logRewrittenUrl="true" /></rule>
RULE 3:
<rule name="AddFolderBackInURLMainSite" enabled="true" stopProcessing="false"><match url="^SUB/([/\-\.0-9a-z]*)" /> <action type="Rewrite" url="{HTTP_X_ORIGINAL_COMMERCIAL_URI}" logRewrittenUrl="true" /></rule>
Preserving the original url hit by user in "HTTP_X_ORIGINAL_COMMERCIAL_URI" server variable in Rule 1. In Rule 2, redirecting to some other url so that user will see change in url browser. In Rule 3, rewriting back to original url hit by user i.e. store in "HTTP_X_ORIGINAL_COMMERCIAL_URI" server variable.
The problem i am facing is that on Rule 3, "HTTP_X_ORIGINAL_COMMERCIAL_URI" server variable is reset to blank, don't know why?
Please help me to provide me is there any other way i can fix this problem or what i am doing wrong in above mentioned implementation.
Thanks in advance.
~Deepak