Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect a domain to another domain in ASP.NET

I have a website with two domains and one hosting server that worked fine with this two URL.
domains are www.jongeshadi.com and www.jongeshadi.ir.
I want when a user typed www.jongeshadi.irredirect to www.jongeshadi.com.
I Google it and find some solution such as change web config to:

<rewrite>
        <globalRules>
          <rule name="Redirects to www.jomgeshadi.com" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^jongeshadi.*(ir|com)$" />
              <add input="{HTTP_HOST}" pattern="^(www.)?jonsgeshadi.(ir|com)$" />
              <add input="{HTTP_HOST}" pattern="^www.jongeshadi.com$" />
            </conditions>
            <action type="Redirect" url="http://www.domain.ir/{R:0}" />
          </rule>
        </globalRules>
    </rewrite>  

But it doesn't worked.any thing is mistake or is there other solution?

like image 821
Hamid Talebi Avatar asked Nov 22 '25 18:11

Hamid Talebi


1 Answers

With modern version of IIS, the easiest way to achieve this is by using URL Rewrite 2.0. It can be installed as a package using Microsoft's Web Platform Installer.

Once you have the rewrite module installed, it adds a URL Rewrite feature in IIS Manager when the website is selected in the tree view.

URL Rewrite in IIS Manager

Inside the URL Rewrite feature, choose "Add rule(s)..." from the right-hand side bar, and then choose to add a "Canonical domain name" rule. Specify the primary host name you want to be the one to display and hit OK.

The add rule dialog box

Selecting your primary host name

That's all there is to it.

like image 131
Richard Fawcett Avatar answered Nov 24 '25 09:11

Richard Fawcett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!