PHP缃戠珯301瀹氬悜鏂规硶璇﹁В

2013 年 10 月 9 日5120

銆 鍏充簬301閲嶅畾鍚戠殑濂藉勶紝鍜屼竴鑸301閲嶅畾鍚戠殑鏂规硶锛岀綉涓婃湁寰堝氾紝绗旇呭氨涓嶉噸澶嶄簡锛屼粖澶╄佽寸殑锛屾槸PHP缃戠珯閫氳繃淇鏀筆HP缃戦〉鐨勫舰寮忓仛濂301閲嶅畾鍚戙

銆 鍓嶆垫椂闂达紝绗旇呯綉绔欐洿鎹㈠煙鍚嶏紝鍦ㄥ仛301閲嶅畾鍚戞椂锛屾悳绱浜嗙綉涓婂緢澶氬笘瀛愶紝鍙戠幇寰堝氶兘缃楀垪浜嗗悇绉嶆柟娉曪紝鍗撮兘娌℃湁鍏蜂綋灏嗘庝箞鎿嶄綔锛屾瘮濡侾HP缃戠珯锛屽氨鏄鍐欏嚭涓嬮潰涓娈典唬鐮佷簡浜

PHP浠g爜
<? Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://http://www.zjjv.com//" );?>

銆銆杩欎釜浠g爜鍙閫傚簲浜庣綉绔欒縼绉荤殑鎯呭喌锛屽嵆鏃х珯鍜屾柊绔欏煙鍚嶄笉鍚屻佹牴鐩褰曚篃涓嶇浉鍚岀殑鎯呭喌銆傚傛灉缃戠珯灞炰簬涓涓缃戠珯缁戝畾2涓鍩熷悕锛2涓鍩熷悕鐨勬牴鐩褰曚负鍚屼竴涓锛岄偅涔堬紝灏变細琛屾垚姝诲惊鐜銆傚湪姝わ紝绗旇呭皢PHP缃戠珯301閲嶅畾鍚戞柟娉曞畬鍏ㄦ斁鍑猴紝甯屾湜鑳藉府鍒版柊浜猴紝濡傛灉鏈変笉瓒充箣澶勶紝涔熻烽珮鎵嬫寚鍑猴紝涓嶈儨鎰熸縺銆

銆銆杩欎釜浠g爜鍙閫傚簲浜庣綉绔欓栭〉鐨301閲嶅畾鍚戯紝濡傛灉缃戠珯宸茬粡琚鏀跺綍锛屾垨瀛樺湪澶ч噺鐨勯潪棣栭〉澶栭摼锛岃佸叏閮ㄥ畾鍚戣繃鏉ワ紝閭e氨鏃犺兘涓哄姏浜嗐傛洿鍚堥傜殑鏂规硶鏄浣跨敤.htaccess鏉ュ畾鍚戯紝绠鍗曞揩鎹凤紝涓嶈繃绗旇呬笉鎳傝繖涓锛屽湪姝わ紝绗旇呭皢PHP缃戠珯301閲嶅畾鍚戞柟娉曞畬鍏ㄦ斁鍑猴紝甯屾湜鑳藉府鍒版柊浜猴紝濡傛灉鏈変笉瓒充箣澶勶紝涔熻烽珮鎵嬫寚鍑猴紝涓嶈儨鎰熸縺銆

涓銆佸缓绔嬩竴涓301.inc.php锛堟枃浠跺悕鑷鍙栵級
<?php
$the_host = $_SERVER['HTTP_HOST'];//鍙栧緱杩涘叆鎵杈撳叆鐨勫煙鍚
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//鍒ゆ柇鍦板潃鍚庨潰閮ㄥ垎
if($the_host !== 'http://www.zjjv.com/')//杩欐槸鎴戣佷互鍓嶇殑鍩熷悕鍦板潃
{
header('HTTP/1.1 301 Moved Permanently');//鍙戝嚭301澶撮儴
header('Location: http://http://www.zjjv.com//'.$request_uri);//璺宠浆鍒版垜鐨勬柊鍩熷悕鍦板潃
}
?>

鍏朵腑if($the_host !== 'http://www.zjjv.com/')涓鐨“!==”鏄涓嶅畬鍏ㄧ瓑浜庣殑鎰忔濓紝涔熷彲浠ョ敤“!=”涓嶇瓑浜庯紝杩欐牱锛屽氨鍙浠ュ皢浠ュ墠鐨勫煙鍚嶏紝鍖呮嫭gcxirang.com銆亀ww.xxx.com浠ュ強鏂板煙鍚嶄腑鎴慻cidc.net鍏ㄩ儴閲嶅畾鍚戝埌http://www.zjjv.com/銆

浜屻佸湪缃戦〉鏂囦欢涓璋冪敤301.inc.php
<?php include("301.inc.php"); //301閲嶅畾鍚 ?>
灏嗚繖涓浠g爜鏀惧埌浣犳墍鏈夌綉椤电殑鏈鍓嶉潰銆

濂戒簡锛岄噸瀹氬悜灏卞仛濂戒簡锛屽皢301鏂囦欢涓婁紶鍒扮綉绔欑洰褰曪紝灏卞彲浠ュ幓鐪嬬潃浣犵殑鎴愭灉浜嗐
鏈鍚庯紝鎻愪緵涓涓缃戝潃锛岄噷闈㈢殑301鏂规硶姣旇緝鍏╤ttp://http://www.zjjv.com//seo/HTTP-Header-301-Moved-Permanently.html
杩樿佹劅璋涓婼EO鍗婁憨鐢扮殑SEO灏忓伐缁欎簣鐨勫ぇ閲忔妧鏈甯鍔╋紝鐪熸槸涓濂戒汉銆

0 0