多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Php實現301重定向跳轉代碼

Php實現301重定向跳轉代碼

來源:程序員人生   發布時間:2014-04-07 19:40:23 閱讀次數:2793次

在php中301重定向實現方法很簡單我們只要簡單的利用header發送301狀態代碼,然后再用header進行跳轉,效果與apache,iis,nginx都是一樣的效果哦。

一:更推薦這種方法,因為它可以把www.phpfensi.com原來所有的url都轉到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上,否則轉到錯誤頁,代碼如下:

  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"); 

附上其它跳轉辦法,代碼如下:

  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. //轉到一個新地址 
  28. header('Location: http://www.example.org/'); 
  29. //文件延遲轉向: 
  30. header('Refresh: 10; url=http://www.example.org/'); 
  31. print 'You will be redirected in 10 seconds'
  32. //當然,也可以使用html語法實現 
  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. //告訴瀏覽器文檔內容沒有發生改變 
  43. header('HTTP/1.1 304 Not Modified'); 
  44. //設置內容長度 
  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. //設置內容類型: 
  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'

跳轉要注意以下幾點,有助于解決一些新手經常遇到的問題

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

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

3、header后的PHP代碼還會被執行。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 尤物在线视频 | 欧美成人免费网在线观看 | 欧美一级精品 | 国产精品久久一区 | 免费在线观看a | 亚洲一区影院 | 国产精品成人一区二区不卡 | 色婷婷91| 日本精高清区一 | 日本特黄特黄刺激大片免费 | 欧美黄色片在线观看 | 久久久久国产精品美女毛片 | 亚洲一区二区中文 | 国产三级在线观看播放 | 国产a级一级久久毛片 | 日本大片免费一级 | 国内视频自拍在线视频 | 亚洲美女啪啪 | 亚洲三级视频在线 | 一区二区高清视频在线观看 | 中文字幕日本一本二本三区 | 亚洲精品国产一区二区在线 | 羞羞影院免费观看网址在线 | 日本vs黑人hd | 波多野结衣在线观看视频 | 最新亚洲人成网站在线影院 | 亚洲精品视频久久久 | 精品国产一区二区三区四 | 91亚洲国产成人久久精品网站 | 午夜视频日本 | 高清在线精品一区二区 | 涩涩五月天婷婷丁香综合社区 | 亚洲专区一路线二 | 2019精品手机国产品在线 | 亚洲精品蜜桃久久久久久 | 国产福利资源在线 | 91成人午夜精品福利院在线观看 | 欧美最猛黑人xxxx黑人猛交 | 波多野氏免费一区 | 永久看片 | 亚洲欧美国产一区二区三区 |