Reputation: 152
I am trying to rewrite/redirect a url in ASP.NET 4.0
Example:
Requested URL:
http://www.domain.com/accounting/blog/post/2009/07/17/Getting-the-most-out-of-your-account-firm.aspx
Rewritten/Redirected URL:
http://blog.domain.com/post/2009/07/17/Getting-the-most-out-of-your-outplacement-firm.aspx
In other words, change the sub-domain from "www" to "blog", and remove "/accounting/blog" from the directory structure, then redirect.
Here is the rule I am using (passes pattern matching tests in IIS, but does not work):
<rewrite>
<rules>
<rule name="blog redirect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="www\.domain\.com\/accounting\/blog\/(.*)" />
</conditions>
<action type="Redirect" url="http://blog.domain.com/{C:1}" />
</rule>
</rules></rewrite>
Any help would be greatly appreciated.
Upvotes: 1
Views: 2036
Reputation: 3279
This will work for any domain:
<rules>
<rule name="blog redirect" stopProcessing="true">
<match url="^accounting/blog/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^www\.(.*)" />
</conditions>
<action type="Redirect" url="http://blog.{C:1}/{R:1}" />
</rule>
</rules>
Upvotes: 2