Sunday, September 16, 2012

redirect to another domain without the url changing || Redirect to another domain using URL Rewriting

This post will describes how to use Url rewriting concept to redirect and rewrite the url in asp.net applications.In URL rewriting we can use regular expression to check the conditions based on requirement.Here i have given a rule for redirect to other domain  when loading specific page in the website which has different domain names.Then the application redirect to "mydomaintest" domain home page when "home-live.aspx" will loaded.
<rule name="MBR-Enterprises" stopProcessing="true">
<match url="^home-live-(.*)$" />
<conditions>
<add input ="{HTTP_HOST}" pattern ="www\.mydomain\.com"  />
</conditions>
<action type="Redirect" url="http://www.mytestapp.com/home-live-{R:1}" redirectType="Permanent" appendQueryString="false" />
</rule>
Redirect to another domain using domain Name:
Here we have to check only the domain name to redirect to desired domain
<rule name="MBR-Enterprises" stopProcessing="true">
<match url="^$" />
<conditions>
<add input ="{HTTP_HOST}" pattern ="www.myapp.com"  />
</conditions>
<action type="Redirect" url="http://www.mytestapp.com" redirectType="Permanent" appendQueryString="false" />
</rule>

No comments:

Bel