怎么做301重定向

2011-03-19 at 05:38 下午 宽宽

非常经典的内容,经常有新人问,省的他们翻搜索引擎了。

1、IIS下301设置

Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择"资源的永久重定向"。

2、ASP下的301转向代码

  1. <%@ Language=VBScript %>
  2. <%
  3. Response.Status=”301 Moved Permanently
  4. Response.AddHeaderLocation”, “http://www.kuankuan.net/2011/03/19/how-to-do-a-301-redirect/”
  5. %>

3、ASP.Net下的301转向代码

  1. <script runat=”server”>
  2. private void Page_Load(object sender, System.EventArgs e)
  3. {
  4. Response.Status = “301 Moved Permanently”;
  5. Response.AddHeader(Location”,”http://www.kuankuan.net/2011/03/19/how-to-do-a-301-redirect/“);
  6. }
  7. </script>
  8. ?>

4、PHP下的301转向代码

  1. header(HTTP/1.1 301 Moved Permanently);
  2. header(Location: http://www.kuankuan.net/2011/03/19/how-to-do-a-301-redirect/”);
  3. exit();
  4. ?>

5、CGI Perl下的301转向代码

  1. $q = new CGI;
  2. print $q->redirect(http://www.kuankuan.net/”);
  3. ?>

6、JSP下的301转向代码

  1. <%
  2. response.setStatus(301);
  3. response.setHeader(Location”, “http://www.kuankuan.net/” );
  4. response.setHeader(Connection”, “close);
  5. %>
  6. ?>

7、Apache下301转向代码

新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

1)将不带WWW的域名转向到带WWW的域名下

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^kuankuan.cn [NC]
  4. RewriteRule ^(.*)$ http://www.kuankuan.net/$1 [L,R=301]

2)重定向到新域名

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^(.*)$ http://www.kuankuan.net/$1 [L,R=301]

3)使用正则进行301转向,实现伪静态

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^news-(.+)\.html$ news.php?id=$1

将news.php?id=123这样的地址转向到news-123.html

8、Apache下vhosts.conf中配置301转向

为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:

  1. <VirtualHost *:80>
  2. ServerName www.kuankuan.cn
  3. DocumentRoot /home/kuankuan
  4. </VirtualHost>
  5.  
  6. <VirtualHost *:80>
  7. ServerName kuankuan.cn
  8. RedirectMatch permanent ^/(.*) http://www.kuankuan.net/$1
  9. </VirtualHost>

Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。

301转向情况检测

http://www.seoconsultants.com/tools/headers.asp
http://www.internetofficer.com/seo-tool/redirect-check/

------------------------------------------------------------------------------------------
作者:
宽宽@网站策划运营
本站所有文章均为宽宽原创。
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。

52 Responses to “怎么做301重定向”

  1. Buy@Cheap.Abana” rel=”nofollow”>..

    Buygeneric pills…

  2. Purchase@Abilify.Online” rel=”nofollow”>…

    Buywithout prescription…

  3. Buy@Generic.Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>…

    Buywithout prescription…

  4. Purchase@Discount.Acai” rel=”nofollow”>..

    Buywithout prescription…

  5. Buy@Acai.Without.Prescription” rel=”nofollow”>…

    Buynow…

  6. Buy@Cheap.Coral.Calcium” rel=”nofollow”>.

    Buynow it…

  7. Buy@Cheap.Coral.Calcium” rel=”nofollow”>…

    Buygeneric meds…

  8. Cheap@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric drugs…

  9. Order@Discount.Abana” rel=”nofollow”>..

    Buygeneric meds…

  10. Buy@Abilify.Online” rel=”nofollow”>..

    Buynow it…

  11. Buy@Cheap.Abilify” rel=”nofollow”>…

    Buygeneric pills…

  12. Cheap@Abilify.Without.Prescription” rel=”nofollow”>..

    Buyno prescription…

  13. Order@Accupril.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  14. Buy@Discount.Accutane” rel=”nofollow”>.…

    Buynow it…

  15. .

    Buygeneric drugs…

  16. Order@Cheap.Actos” rel=”nofollow”>.

    Buygeneric drugs zfk…

  17. Actos@15mg.30mg.Without.Prescription” rel=”nofollow”>..

    Buygeneric meds qmo…

  18. Cheap@Coral.Calcium.Online” rel=”nofollow”>…

    Buywithout prescription xiu…

  19. Buy@Cheap.Accupril” rel=”nofollow”>.

    Buygeneric drugs nih…

  20. Cheap@Accutane.10mg.20mg” rel=”nofollow”>.

    Buyit now ojb…

  21. Order@Aciphex.Online” rel=”nofollow”>.

    Buynow it lmg…

  22. Order@Discount.Aciphex” rel=”nofollow”>…

    Buygeneric meds svb…

  23. Cheap@Advair.Without.Prescription” rel=”nofollow”>…

    Buyit now sge…

  24. Buy@Cheap.Aggrenox” rel=”nofollow”>..

    Buygeneric meds dxy…

  25. Buy@Cheap.Aldactone” rel=”nofollow”>..

    Buydrugs without prescription hak…

  26. actonel@and.heart.irregularities” rel=”nofollow”>..

    Buyno prescription…

  27. aldactone@kidney.problems” rel=”nofollow”>…

    Buygeneric drugs…

  28. actonel@and.dvt” rel=”nofollow”>.

    Buygeneric meds…

  29. levaquin 500mg

    Buy_no prescription…

  30. drug test company

    Buy_without prescription…

  31. depression medcine xr

    Buy_drugs without prescription…

  32. herbals for pregnancy

    Buy_drugs without prescription…

  33. best@medicare.plan.d.for.nexium.40.mg” rel=”nofollow”>..

    Buygeneric meds…

  34. infant@prevacid.dose” rel=”nofollow”>.

    Buygeneric drugs…

Leave a Reply