可用客戶端觸發或服務端觸發的方式來實現頁面跳轉。
客戶端觸發
方式一:使用Javascript
利用window.location對象的href屬性、assign()方法或replace()方法來實現。
<script> //使用href屬性跳轉
location.href ='https://www.sogou.com';
//或者,使用assign()方法跳轉
location.assign('https://www.sogou.com');
//或者,使用replace()方法跳轉
location.replace('https://www.sogou.com'); </script>
方式二:使用Html中<meta>標簽來定義頁面的元信息
<!-- 5秒鍾后跳轉到指定頁面 --> <meta http-equiv="refresh" content="5;url=http://www.baidu.com"/>
以上2種方式只是單純的跳轉,既不是重定向301也不是302。
服務端觸發
使用PHP的header()函數
//使用302重定向跳轉 header('Location:https://www.sogou.com'); //或者,使用301重定向跳轉 (301和302有區別,注意使用) header('HTTP/1.1 301 Moved Permanently'); header('Location: https://www.sogou.com'); //注意:header()函數前不能有輸出
(重定向301和302的區別見 http://www.cnblogs.com/shenxinpeter/p/5899204.html)
另外,還可以在Web服務器軟件如apache中配置Rewrite來實現頁面跳轉。
最后,上面這些跳轉對搜索引擎友好的只有301重定向。