網址的首選域統一非常重要,如果網站綁定兩個域名,那么在選定一個主域名后,另外一個域名就要301跳轉到主域名,PHPwind的論壇如果想要將不帶www的跳轉到www的域名,可以使用PHP代碼做301跳轉.
PHPwind論壇的頁面都調用的一個文件是global.php,將下面一段代碼放入global.php可以實現整個論壇的301跳轉(將http://AAA.com/跳轉到http://www.AAA.com/):
- $the_floor = $_SERVER['HTTP_HOST'];
- $floor_pageurl=str_replace(".php?", "-htm-", $_SERVER[REQUEST_URI]);
- //因為做了偽靜態所以將網址中的.php?替換成-htm-
- if($floor_pageurl == '/index.php')
- //如果是首頁的話,將網址設為空。
- {
- $floor_pageurl='/';
- }
- if($the_floor == 'Vevb.com')
- {
- header('HTTP/1.1 301 Moved Permanently');
- header('Location:http://www.companysz.com'.$floor_pageurl);
- }
將上面這段代碼放到global.php文件這段代碼下面就可以了:
- file_exists('install.php') && header('Location: ./install.php');
- error_reporting(E_ERROR | E_PARSE);
- set_magic_quotes_runtime(0);
- function_exists('date_default_timezone_set') && date_default_timezone_set('Etc/GMT+0');
其實如果服務器支持(比如是IIS7以上的服務器),則可以使用Web.config的301跳轉代碼,使用Linux操作系統的則可以使用.htaccess的301跳轉.
新聞熱點
疑難解答
圖片精選