我們從前年、去年開始就縮減了一些以前的多語言網站,将很少人訪問的語言取消掉,取消語言後的跳轉以前是在.htaccess中設置的,同事處理起來比較麻煩,現在幹脆寫了一段代碼放在html.tpl.php的開頭位置,從當前網址中分離出可能的語言代碼,如果是已經取消的就301跳轉到默認語言對應的網址去,PHP程序代碼如下:
//jamesqi 2021-6-29 not availabled languages 301 redirect to default language
$server_name = $_SERVER['SERVER_NAME'];
$request_uri = $_SERVER['REQUEST_URI'];
$request_uri_path1 = strtok($request_uri, "/");
$request_uri_path1 = strtok($request_uri_path1, "?");
//print "request_uri_path1 = $request_uri_path1, "; //可能的語言路徑
$request_uri_path2 = substr($request_uri, strlen($request_uri_path1) + 1);
//print "request_uri_path2 = $request_uri_path2, "; //'/5/edit?destination=admin/content'//可能的默認語言路徑
$language_list_predefined_array = array_keys(_locale_prepare_predefined_list());
//print_r($language_list_predefined_array);//所有預定義語言
$language_list_added_array = array_keys(language_list());
//print_r($language_list_added_array);//添加的語言
$language_list_enabled_array = array_keys(language_list('enabled')[1]);
//print_r($language_list_enabled_array);//開啟的語言
if ((in_array($request_uri_path1, $language_list_predefined_array) || in_array($request_uri_path1, $language_list_added_array)) && !in_array($request_uri_path1, $language_list_enabled_array)) {
$location_url = "https://{$server_name}{$request_uri_path2}";
//print "location_url = $location_url, ";
header("Location: $location_url", TRUE, 301);
exit;
}
注意如果有amp版本,還需要把amp版本的html.tpl.php也做一樣的修改。
评论2
祁老師
祁老師 請問adsense廣告在沒有廣告顯示的時候不能自動收起 這樣就會出現很大一個空白區域 怎樣才能避免呢?你好,在另一個頁面中回答了:“這個問題還沒有好的辦法解決”
你好,在另一個頁面中回答了:“這個問題還沒有好的辦法解決”。