apache, iis 301 setup tutorial (for virtual hosting)
Published: 2014-12-24
The currently provided tutorial implements 301 through rewrite rules. At present, our company's hosting control panel has developed a "301 Redirect" feature for quick setup:
If HTTPS access is deployed, please ignore this tutorial. For websites deployed with HTTPS, please refer to:https://www.west.cn/faq/list.asp?unid=1419
Go to Business Management - Virtual Host Management - 301 Redirect

After entering, it is as shown in the figure
2.1 Windows 2008/2012/2016 systems:

In the first box, enter the domain that needs to be redirected when accessed; in the second box, enter the domain to redirect to.
2.2 Linux system:

In the left selection box, select the domain(s) that need to be redirected. If there are multiple domains, drag to multi-select or hold the Ctrl key and click.
In the right selection box, enter the domain to redirect to. The generated 301 code will be displayed below. You need to create a file under wwwroot via Website Basic Functions - File Management, name it .htaccess (if it already exists, just copy the code and add it). Copy the generated code, paste it into .htaccess, and save.
The method for manually setting up 301 is as follows:
Apache rules
In the hosting control panel - File Management, enter wwwroot, create a new file, name it .htaccess, write the following rules, and save.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxxx1.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^xxxx2.com$ [NC]
RewriteRule ^(.*)$ http://www.xxxx1.com/$1 [R=301,L]
</IfModule>The effect achieved is that when xxxx.com is accessed, it redirects to www.xxxx.com. RewriteCond is the condition; for multiple domains, just copy one more line.
IIS rules
In the hosting control panel - File Management, enter wwwroot, create a new file, name it web.config, copy some rules, and save.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^xxxx1.com$" />
<add input="{HTTP_HOST}" pattern="^xxxx2.com$" />
</conditions>
<action type="Redirect" url="http://www.xxxx1.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>The effect achieved is that when xxxx1.com and xxxx2.com are accessed, they redirect to www.xxxx1.com.
