国产精品成人VA在线观看,亚洲日韩在线中文字幕综合,亚洲AV电影天堂男人的天堂,久久人人爽人人爽人人av东京热

News新聞

業(yè)界新聞動(dòng)態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      PHP header 請(qǐng)求返回狀態(tài)值設(shè)置(301,404)

PHP header 請(qǐng)求返回狀態(tài)值設(shè)置(301,404)

標(biāo)簽: 發(fā)布日期:2014-03-06 00:00:00 633
對(duì)于一個(gè)網(wǎng)絡(luò)程序員來說,網(wǎng)頁請(qǐng)求狀態(tài)碼的合理利用是非常重要的,不僅提升用戶體驗(yàn),對(duì)網(wǎng)優(yōu)化也是非常重要的,下面主要講下經(jīng)常用到的301,和404 處理
掌握PHP設(shè)置301重定向方法
一,直接使用內(nèi)置函數(shù)header
header( "Location: http://tqybw.net", true, 301 );
二,使用HTTP/1.x聲明301重定向
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://tqybw.net" );
注意:http://tqybw.net表示需要重定向的URL
必免重復(fù)URL
案例分析:在做天氣預(yù)報(bào)網(wǎng)時(shí),用戶在搜索'廈門天氣',其實(shí)對(duì)就的URL是http://tqybw.net/xiamen15tian/,但是兩個(gè)URL是沒辦法一致的,所以我們可以考慮用301
1)寫程序通過搜索的詞得出對(duì)就的url ,廈門=>xiamen
2) 得到對(duì)應(yīng)的程序后做301處理;
header( "Location: http://tqybw.net/xiamen15tian/",true,301 );
exit();
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://tqybw.net/xiamen15tian/" );
exit();
注意:location后的URL必須是完整的URL地址,如下:
NOT:tqybw.net/xiamen15tian/
YES:http://tqybw.net/xiamen15tian/
PHP內(nèi)置header等函數(shù)資料
一,header 函數(shù) 送出 HTTP 協(xié)議的標(biāo)頭到瀏覽器,header參考資料
header ( string string [, bool replace [, int http_response_code]] )
例:PHP實(shí)現(xiàn)404未找到方法
header('HTTP/1.1 404 Not Found'); 
header("status: 404 Not Found"); 
include('404.php'); //404提示頁
exit();