Answer the question
In order to leave comments, you need to log in
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
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>
<?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>
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/
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
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 questionAsk a Question
731 491 924 answers to any question