apache、iis、nginx设置301重定向
admin
2019-08-08 PM
367℃
0条
apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxxx1.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^xxxx2.com$ [NC]
# RewriteCond %{HTTP_HOST} !^www.xxxx1.com$ [NC]
RewriteRule ^(.*)$ http://www.xxxx1.com/$1 [R=301,L]
</IfModule>
iis
ii6通过isapi重写组件
RewriteCond %{HTTP:Host} ^xxxx1.com$ [NC]
RewriteCond %{HTTP:Host} ^xxxx2.com$ [NC]
RewriteRule (.*) http://www.xxxx1.com$1 [NC,R=301]
iis7以上web.config
<?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>
nginx
添加到配置文件server段内
server
{
listen 80;
server_name abc.com;
rewrite ^(.*) http://www.abc.com$1 permanent;
}
if ($host != 'www.abc.com' ) {
rewrite ^/(.*)$ http://www.abc.com/$1 permanent;
}