linux系统手工设置301的方法如下:
在主机面板-文件管理,进入wwwroot,新建一个文件,命名为.htaccess文件,写入以下规则,保存即可
<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>实现的效果是xxxx.com访问时跳转到www.xxxx.com RewriteCond为条件,多域名时多复制一行即可
apache环境:
在网站根目录下创建一个.htaccess文件,然后写入以下规则,如果文件本身就存在,在里面添加以下规则,即可跳转https访问。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC] # 将abc.com和www.abc.com跳转到https://www.abc.com,防止apache子站继承上级目录.htaccess受影响
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
</IfModule>Nginx环境:
iis规则
在主机面板-文件管理,进入wwwroot,新建一个文件,命名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>实现的效果是xxxx1.com和xxxx2.com访问时跳转到www.xxxx1.com
在网站根目录下创建web.config文件,写入一下代码。如果web.config本身就存在,在<system.webServer>配置节点后添加<rewrite>.......</rewrite> 这一段规则内容,即可跳转https访问。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.abc.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>