日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > php教程 > Php實現(xiàn)301重定向跳轉(zhuǎn)代碼

Php實現(xiàn)301重定向跳轉(zhuǎn)代碼

來源:程序員人生   發(fā)布時間:2014-04-07 19:40:23 閱讀次數(shù):2806次

在php中301重定向?qū)崿F(xiàn)方法很簡單我們只要簡單的利用header發(fā)送301狀態(tài)代碼,然后再用header進行跳轉(zhuǎn),效果與apache,iis,nginx都是一樣的效果哦。

一:更推薦這種方法,因為它可以把www.phpfensi.com原來所有的url都轉(zhuǎn)到phpfensi.com新的地址上,代碼如下:

  1. <?php 
  2. $the_host = $_SERVER['HTTP_HOST']; 
  3. $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''
  4. if($the_host == 'www.phpfensi.com'
  5. header('HTTP/1.1 301 Moved Permanently'); 
  6. header('Location: http://phpfensi.com'.$request_uri);// 
  7. ?> 

二:單頁多站的Php301重定向代碼,www.phpfensi.com和phpfensi.com則301到index.php上,www.phpfensi.com則301到phpfensi.com上,否則轉(zhuǎn)到錯誤頁,代碼如下:

  1. if(($HTTP_HOST=="www.phpfensi.com")or($HTTP_HOST=="phpfensi.com")) 
  2. header("HTTP/1.1 301 Moved Permanently"); 
  3. Header("Location: /index.php"); 
  4. elseif($HTTP_HOST=="www.phpfensi.com"
  5. header("HTTP/1.1 301 Moved Permanently"); 
  6. Header("Location: http://phpfensi.com"); 
  7. else 
  8. Header("Location: /404.htm"); 

附上其它跳轉(zhuǎn)辦法,代碼如下:

  1. //定義編碼 
  2. header( 'Content-Type:text/html;charset=utf-8 '); 
  3. //Atom 
  4. header('Content-type: application/atom+xml'); 
  5. //CSS 
  6. header('Content-type: text/css'); 
  7. //Javascript 
  8. header('Content-type: text/javascript'); 
  9. //JPEG Image 
  10. header('Content-type: image/jpeg'); 
  11. //JSON 
  12. header('Content-type: application/json'); 
  13. //PDF 
  14. header('Content-type: application/pdf'); 
  15. //RSS 
  16. header('Content-Type: application/rss+xml; charset=ISO-8859-1'); 
  17. //Text (Plain) 
  18. header('Content-type: text/plain'); 
  19. //XML 
  20. header('Content-type: text/xml'); 
  21. // ok 
  22. header('HTTP/1.1 200 OK'); 
  23. //設置一個404頭: 
  24. header('HTTP/1.1 404 Not Found'); 
  25. //設置地址被永久的重定向 
  26. header('HTTP/1.1 301 Moved Permanently'); 
  27. //轉(zhuǎn)到一個新地址 
  28. header('Location: http://www.example.org/'); 
  29. //文件延遲轉(zhuǎn)向: 
  30. header('Refresh: 10; url=http://www.example.org/'); 
  31. print 'You will be redirected in 10 seconds'
  32. //當然,也可以使用html語法實現(xiàn) 
  33. // <meta http-equiv="refresh" content="10;http://www.example.org/ /> 
  34. // override X-Powered-By: PHP: 
  35. header('X-Powered-By: PHP/4.4.0'); 
  36. header('X-Powered-By: Brain/0.6b'); 
  37. //文檔語言 
  38. header('Content-language: en'); 
  39. //告訴瀏覽器最后一次修改時間 
  40. $time = time() - 60; // or filemtime($fn), etc 
  41. header('Last-Modified: '.gmdate('D, d M Y H:i:s'$time).' GMT'); 
  42. //告訴瀏覽器文檔內(nèi)容沒有發(fā)生改變 
  43. header('HTTP/1.1 304 Not Modified'); 
  44. //設置內(nèi)容長度 
  45. header('Content-Length: 1234'); 
  46. //設置為一個下載類型 
  47. header('Content-Type: application/octet-stream'); 
  48. header('Content-Disposition: attachment; filename="example.zip"'); 
  49. header('Content-Transfer-Encoding: binary'); 
  50. // load the file to send: 
  51. readfile('example.zip'); 
  52. // 對當前文檔禁用緩存 
  53. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); 
  54. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past 
  55. header('Pragma: no-cache'); 
  56. //設置內(nèi)容類型: 
  57. header('Content-Type: text/html; charset=iso-8859-1'); 
  58. header('Content-Type: text/html; charset=utf-8'); 
  59. header('Content-Type: text/plain'); //純文本格式 
  60. header('Content-Type: image/jpeg'); //JPG*** 
  61. header('Content-Type: application/zip'); // ZIP文件 
  62. header('Content-Type: application/pdf'); // PDF文件 
  63. header('Content-Type: audio/mpeg'); // 音頻文件 
  64. header('Content-Type: application/x-shockw**e-flash'); //Flash動畫 
  65. //顯示登陸對話框 
  66. header('HTTP/1.1 401 Unauthorized'); 
  67. header('WWW-Authenticate: Basic realm="Top Secret"'); 
  68. print 'Text that will be displayed if the user hits cancel or '
  69. print 'enters wrong login data'

跳轉(zhuǎn)要注意以下幾點,有助于解決一些新手經(jīng)常遇到的問題

1、location和“:”號間不能有空格,否則會出錯。

2、在用header前不能有任何的輸出。

3、header后的PHP代碼還會被執(zhí)行。

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲一区二区三区四区视频 | 久久久久久久综合 | 亚洲一区二区在线视频 | 国产精品乱码一区二区三区 | av中文字幕第一页 | 亚洲日本视频 | 一区二区三区不卡在线观看 | 婷婷99狠狠躁天天躁中文字幕 | 免费黄色在线观看 | 国产精品毛片一区二区三区 | 91精品国产色综合久久 | 99色网| 久久国产精品免费一区二区三区 | 国产精品一区二区久久久 | 日韩欧美在线看 | 在线观看视频免费播放 | 天堂在线中文 | 日韩精品中文字幕一区二区三区 | 十八岁网站 | 成人免费av | 国产毛片精品 | 日韩视频一级 | 成人97视频 | 91一区二区三区 | 亚洲精品三级 | 中日韩在线观看 | 日韩三级| 欧美一区二区三区影视 | 国内外成人在线视频 | 欧美精品一区二区三区四区五区 | 黄色一级片在线免费观看 | 久久久二区| 一级黄视频| 美女国内精品自产拍在线播放 | 国产精品9 | 成人午夜电影在线观看 | 久久久国产精品 | 久久久久久久网站 | 91精品国产综合久久国产大片 | 成人在线视频网址 | www.在线播放|