网站之家技术交流论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1336|回复: 0

最新最全的301跳转代码全集-包含ASP|PHP|JSP|.NET

[复制链接]
发表于 2013-3-15 04:22:00 | 显示全部楼层 |阅读模式
  1. 1、IIS下301设置
  2. Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择“资源的永久重定向”。
  3. 2、ASP下的301转向代码
  4. <%@ Language=VBScript %>
  5. <%
  6. Response.Status=”301 Moved Permanently”
  7. Response.AddHeader “Location”, “http://www.ahwebs.com/articles/301/”
  8. %>
  9. 3、ASP.Net下的301转向代码
  10. <script runat=”server”>
  11. private void Page_Load(object sender, System.EventArgs e)
  12. {
  13. Response.Status = “301 Moved Permanently”;
  14. Response.AddHeader(”Location”,”http://www.ahwebs.com/articles/301/“);
  15. }
  16. </script>
  17. 4、PHP下的301转向代码
  18. header(”HTTP/1.1 301 Moved Permanently”);
  19. header(”Location: http://www.ahwebs.com/articles/301/”);
  20. exit();
  21. 5、CGI Perl下的301转向代码
  22. $q = new CGI;
  23. print $q->redirect(”http://www.new-url.com/”);
  24. 6、JSP下的301转向代码
  25. <%
  26. response.setStatus(301);
  27. response.setHeader( “Location”, “http://www.ahwebs.com/” );
  28. response.setHeader( “Connection”, “close” );
  29. %>
  30. 7、Apache下301转向代码
  31. 新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
  32. 1)将不带WWW的域名转向到带WWW的域名下
  33. Options +FollowSymLinks
  34. RewriteEngine on
  35. RewriteCond %{HTTP_HOST} ^lesishu.cn [NC]
  36. RewriteRule ^(.*)$ http://www.ahwebs.com/$1 [L,R=301]
  37. 2)重定向到新域名
  38. Options +FollowSymLinks
  39. RewriteEngine on
  40. RewriteRule ^(.*)$ http://www.ahwebs.com/$1 [L,R=301]
  41. 3)使用正则进行301转向,实现伪静态
  42. Options +FollowSymLinks
  43. RewriteEngine on
  44. RewriteRule ^news-(.+)\.html$ news.php?id=$1
  45. 将news.php?id=123这样的地址转向到news-123.html
  46. 8、Apache下vhosts.conf中配置301转向
  47. 为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:
  48. <VirtualHost *:80>
  49. ServerName www.ahwebs.com
  50. DocumentRoot /home/lesishu
  51. </VirtualHost>
  52. <VirtualHost *:80>
  53. ServerName lesishu.cn
  54. RedirectMatch permanent ^/(.*) http://www.ahwebs.com/$1
  55. </VirtualHost>
  56. Apache下除了以上2种方法,还有其他配置方法和可选参数
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|网站之家技术交流论坛 ( 粤ICP备09092995号 )

GMT+8, 2024-5-21 18:15 , Processed in 0.094124 second(s), 7 queries , File On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表