301重定向

交互设计

  301重定向

  一、什么是301重定向。

  301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址。

  二、什么情况下使用301重定向。

  网站更换域名时,通过301永久重定向将旧域名重定向至新域名,挽回流量损失和SEO;如果你有多个闲置域名时需要指向同一网站时,可以通过301永久重定向实现;你打算实现网址规范化,例如:不带www的域名和带www的域名,实现网址的统一。

  三、如何编写301重定向。

  1、web服务器apache主机(linux)

  进入虚拟主机根目录,新建.htaccess文件。代码如下

  <IfModule mod_rewrite.c>

  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^iconbaidu.com$ [NC]

  RewriteRule ^(.*)$ icon网页链接 [R=301,L]

  </IfModule>

  2、iis7主机(windows)

  进入虚拟主机ftp网站根目录wwwroot or htdocs,找到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="^iconbaidu.com#34; />

  </conditions>

  <action type="Redirect" url="icon网页链接" redirectType="Permanent" />

  </rule>

  </rules>

  </rewrite>

  </system.webServer>

  </configuration>

标签: 交互设计