找回密码
 加入
搜索

[代码] 301重定向跳转方式

[复制链接]
发表于 2006-8-22 06:30:09 | 显示全部楼层 |阅读模式
一般跳转有三种,通过asp或php程序,页面中meta和js跳转。

其中,meta和js跳转都属于302跳转,301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。

以下是一些我整理的代码:
asp:
  1. <%
  2. Response.Status="301 Moved Permanently"
  3. Response.AddHeader "Location","http://www.fohee.net"
  4. %>
复制代码
php:
  1. <?
  2. Header( "HTTP/1.1 301 Moved Permanently" ) ;
  3. Header( "Location: http://www.fohee.net" );
  4. ?>
复制代码
asp.net
  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.fohee.net");
  6. }
  7. </script>
复制代码
apache下设置httpd.conf或者站点的.htaccess

  1. RewriteEngine ON
  2. RewriteRule ^(.*)$ http://www.fohee.net/$1 [R=301,L]
复制代码

  1. Redirect permanent / http://www.fohee.net/ (将目录下所有内容重定向到http://www.fohee.net/相应的内容)
  2. Redirect permanent / http://www.fohee.net/links.php(将网站首页重定向到指定文件:http://www.fohee.net/links.php)
复制代码
此头部有permanent,否则重定向属于302临时重定向,此方法已不常用,通常都用上面的RewriteEngine ON。

IIS下
* 打开internet信息服务管理器,在欲重定向的网页或目录上按右键
* 选择“重定向到URL”
* 在“重定向到”输入框中输入要跳转到的目标网页的URL地址
* 选中“资源的永久重定向”(切记)
* 最后点击“应用”

Archiver|手机版|小黑屋|乱弹琴|重庆网址之家|多来米发 |

GMT+8, 2026-10-13 09:59 PM

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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