I have URL rewriting rules that redirect www.domain2.com to a subfolder under the root of domain1.com (call this subproject of this folder). In my controller, I need to create a URL for the original unmodified path, but the Request.Url properties (for example, AbsoluteUri or LocalPath) always contain a subfolder of the subproject.
In other words, if the user typed:
www.domain2.com/controller/action
urlrewrite does this:
www.domain1.com/subproject/controller/action
and I want to restore the original url:
www.domain2.com/controller/action
I could hard delete the removal of the subproject from url and start the url with domain2, but I need a common piece of code because this url reconstruction will be in the reusable library. domain2 may be in the settings of my application, but what about a subfolder?
The rewrite rule is given as a reference:
<rewrite>
<rules>
<rule name="Redirect to subproject">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?domain2.com" />
<add input="{PATH_INFO}" pattern="^/subproject/" negate="true" />
</conditions>
<action type="Rewrite" url="\subproject\{R:0}" />
</rule>
</rules>
</rewrite>