我目前正在为客户建立一个购物车,但他想要不同国家的不同版本,所以为此我创建了两个名为europe.website.com的子域名和一个名为row.website.com的子域名
On my .htaccess I also have this...
# Make all requests have www in them
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website\.com
RewriteRule ^(.*)$ https://www.website.com/$1 [R=permanent,L]
就这样迫使www。在网站上但这应该对子域名没有影响,但是因为它有'https'我会遇到安全风险,例如。
本网站提供的安全证书是针对a 不同网站的地址。
安全证书问题可能表示企图欺骗您或 拦截您发送到服务器的任何数据。
我们建议您关闭此网页,不要继续关闭此页面 网站。
这就是你可以看到的第一个问题!第二个问题是它没有重定向到那些子域,我无法弄清楚为什么!这是我在主网站上的index.php上使用的php代码块....
<?php
$lc = "";
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
if($lc == array("ab", "ad","ae","af","ag","al","am","ao","aq", "aa", "af", "sq", "am", "ar", "an", "ac", "as", "aw", "ax", "az", "bb", "bd", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg","ci","ck","cl","cm","cn","co","cr","cu","cv","cx","dj","dm","do","dz","ec","ee","eg","eh","er","et","fj","fk","fm","fo","fx","ga","gd","ge","gf","gh","gl","gm","gn","gp","gq","gs","gt","gu","gw","gy","hk","hm","hn","ht","id","il","in","io","iq","ir","is","jm","jo","jp","ke","kg","kh","kl","km","kn","kp","kr","kw","ky","kz","la","lb","lc","lr","ls","ly","ma","md","me","mf","mg","mh","mk","ml","mm","mn","mo","mp","mq","mr","ms","mu","mv","mw","mx","my","mz","na","nc","ne","nf","ng","ni","np","nr","nt","nu","nz","om","pa","pe","pf","pg","ph","pk","pl","pm","pn","pr","ps","pw","py","qa","re","ru","rw","sa","sb","sc","sd","sg","sh","sj","sl","sn","so","sr","ss","st","su","sv","sy","sz","tc","td","tf","tg","th","tj","tk","tm","to","tp","tr","tt","tv","tw","tz","ug","um","us","uy","uz","va","vc","ve","vg","vi","vn","vu","wf","ws","ye","yt","yu","za","zm","zr","zw")){
header("location: https://row.website.com/index.php");
exit();
} else if($lc == array("an", "at", "ba", "be", "ch", "cs", "cy","cz", "de", "dk", "es", "eu", "fl", "fr", "fx", "gi", "gr", "hr", "hu", "ie", "it", "li", "lt", "lu", "lv", "mc", "mt", "nl", "no", "pt", "rs","ro", "se", "sl", "sk", "sm", "tn", "ua", "uk", "xk" )){
header("location: https://europe.website.com/index.php");
exit();
}
?>
当我在英国时,我决定将“uk”添加到重定向到我的欧洲子域的阵列但没有这样的运气并且已经要求州内的其他朋友检查该站点并查看它是否重定向但仍然没有快乐,因为它只停留在主域!
谁有任何线索?提前谢谢!-Phillip Dews
更新
好的,我已经改变了所有这一切,我已经要求国外的人检查网站,但它仍然没有重定向!这是我的代码......
<?php
$lst ['euro'] = array("be","bs",ECT ECT...);
$lst ['other'] = array("ab","aa","af");
$lc = "";
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
else $lc = 'en';
if(in_array($lc, $lst['other'])){
header("location: https://www.WEBSITE.com/row/index.php");
exit();
}
elseif (in_array($lc, $lst['euro'])) {
header("location: https://www.WEBSITE.com/europe/index.php");
exit();
}
else {
header("location: https://www.WEBDESITE.com/index.php");
exit();
}
?>
决定摆脱子域名,因为ssl不能对它们起作用,而只是添加2个新目录!
再一次非常感谢所有人! -Phillip Dews
答案 0 :(得分:0)
$lcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$lcode = explode(",", $lcode['0']);
$lc = $lcode['0'];
但也许这会得到相同的结果......
编辑:只需查看您获得的语言代码? echo $lc;
此外,如果未设置$ _SERVER ['HTTP_ACCEPT_LANGUAGE'],则需要提供默认语言(可能是'en')。
编辑:如果语言代码不在两个阵列中,您还需要重定向到默认域。例如,如果代码为'en'会发生什么?你为什么不在顶部数组中使用'en'?
更新:好的,你的php逻辑语句中也有错误。使用in_array()
,如下所示:
<?php
$lst_euro = array(array("an", "at", ...);
$lst_other = array(array("ab", "ad", ...);
$lc = "";
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
else $lc = 'en';
if(in_array($lc, $lst_other)){
header("location: https://row.website.com/index.php");
exit();
}
elseif(in_array($lc, $lst_euro)) {
header("location: https://europe.website.com/index.php");
exit();
}
else {
header("location: https://row.website.com/index.php");
exit();
}
&GT;