K
K
Kirill Firsov2011-05-12 16:07:27
ASP.NET
Kirill Firsov, 2011-05-12 16:07:27

ASP.NET 301 redirect?

Hello.
There is 1 site, it can be accessed by 3 domains.
site1.com
site2.com
site3.com
It's all the same site.
Need a rule for asp.net that from site3.com & site2.com gave 301 redirects to www.site1.com
Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Valery Abakumov, 2014-06-23
@Valeriy1991

The content of web.config is a really working example (website names have been changed to fake ones), which:
1) when going to www.company.ru redirects to company.ru
2) when going to mysite.com redirects to company.ru
3) when going to to www.mysite.com redirects to company.ru
4) referential integrity is preserved, i.e. when going to www.mysite.com/home/write_to_us redirects to company.ru/home/write_to_us
If it doesn't work, then something is wrong with the URL Rewrite Module in IIS.
On the site mysite.com ( from which there will be a redirect) in web.config we write:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
  <rewrite>
    <rules>			
      <rule name="Condition1" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
          <add input="{HTTP_HOST}" pattern="^(www\.)?mysite\.com$" />
        </conditions>
        <action type="Redirect" url="http://company.ru/{R:1}" redirectType="Permanent" />
      </rule>
      <rule name="Condition2" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^www\.company\.ru" />
        </conditions>
        <action type="Redirect" url="http://company.ru/{R:1}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
  </system.webServer>
</configuration>

On the site company.ru ( which will be redirected) in web.config we write:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to company.ru 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^(www\.)?mysite\.com$" />
          </conditions>
          <action type="Redirect" url="http://company.ru/{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="Redirect to company.ru 2" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
              <add input="{HTTP_HOST}" pattern="^www\.company\.ru" />
          </conditions>
          <action type="Redirect" url="http://company.ru/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  ...
</configuration>

Perhaps Visual Studio itself will swear at you about the presence of the "rewrite" section - it emphasized this section for me. What is the reason - I, to be honest, I don’t remember, but on the site itself everything is already working with a bang.
Good luck!

G
GLuRE, 2011-05-12
@GLuRE

In the .htaccess files (httpd.conf for Apache) on the domains from which you want to redirect, enter the following:
Redirect 301 / www.you.ru/

I
IchWill, 2011-05-12
@IchWill

If you have access to the IIS7 control panel, then create a site there, write site2.com and site3.com in the bindings.
Then click on the HTTP Redirect icon in the control panel and fill out a small form (two checkboxes, input and dropdown), and then on the button apply.
mold

D
Dmitry Filandor, 2015-02-09
@LifeAct

worked for me like this:

<rewrite>
      <rules>
        <rule name="Redirect to non-www" stopProcessing="true">
          <match url="(.*)" negate="false"></match>
          <action type="Redirect" url="http://aforizmus.com/{R:1}"></action>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^aforizmus\.com$" negate="true"></add>
          </conditions>
        </rule>
      </rules>
    </rewrite>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question