国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Php實現301重定向跳轉代碼

2024-05-04 21:57:13
字體:
來源:轉載
供稿:網友

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

一:更推薦這種方法,因為它可以把m.survivalescaperooms.com原來所有的url都轉到Vevb.com新的地址上,代碼如下:

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

二:單頁多站的Php301重定向代碼,m.survivalescaperooms.com和Vevb.com則301到index.php上,m.survivalescaperooms.com則301到Vevb.com上,否則轉到錯誤頁,代碼如下:

  1. if(($HTTP_HOST=="m.survivalescaperooms.com")or($HTTP_HOST=="Vevb.com")) 
  2. header("HTTP/1.1 301 Moved Permanently"); 
  3. Header("Location: /index.php"); 
  4. elseif($HTTP_HOST=="m.survivalescaperooms.com"
  5. header("HTTP/1.1 301 Moved Permanently"); 
  6. Header("Location: http://Vevb.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代碼還會被執行。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 旺苍县| 贡觉县| 青田县| 陵水| 安康市| 长垣县| 永顺县| 黔西县| 库伦旗| 洪泽县| 达尔| 沈丘县| 清新县| 瑞昌市| 英德市| 怀仁县| 盐津县| 乌拉特中旗| 安达市| 凌源市| 泰州市| 清涧县| 四子王旗| 应用必备| 赣榆县| 永嘉县| 当雄县| 博兴县| 江川县| 邵东县| 呈贡县| 昌邑市| 合作市| 儋州市| 瓦房店市| 江陵县| 应城市| 呼伦贝尔市| 和顺县| 澄城县| 资阳市|