gpt4 book ai didi

php - 多语言 .htaccess 重定向到子域

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:33:14 24 4
gpt4 key购买 nike

我在 PHP 中有一个多语言网站(西类牙语、英语、法语),主要语言是英语。

如果 $_SESSION['idm'] 设置为“en”,它会加载包含翻译的文件。

我想这样设置:

如果用户语言是西类牙语

www.mydomain.commydomain.com -> es.mydomain.com

www.mydomain.com/video.php?id=3 -> es.mydomain.com/video.php?id=3

如果用户语言是法语

www.mydomain.com 和 mydomain.com -> fr.mydomain.com

www.mydomain.com/video.php?id=3 -> fr.mydomain.com/video.php?id=3

如果不是以上任何一个

www.mydomain.com 和 mydomain.com -> en.mydomain.com

www.mydomain.com/video.php?id=3 -> en.mydomain.com/video.php?id=3

我该怎么做,这样的 SEO 是否明智?

最佳答案

在 PHP 中:

// check if the current domain is the generic one
$req_domain = $_SERVER['SERVER_NAME'];
if ($req_domain == 'www.mydomain.com' || $req_domain == 'mydomain.com') {
$subdomains = array ('fr' => 'fr.mydomain.com',
'es' => 'es.mydomain.com',
'en' => 'en.mydomain.com');


// get the language from the session variable (if set), or use default
$lang = 'en'; // default language
if ( isset($_SESSION['idm']) && isset($subdomains[$_SESSION['idm']]) )
$lang = $_SESSION['idm']; // selected language


// redirect while maintaining the complete request URI
header('Location: http://' . $domains[$lang] . $_SERVER['REQUEST_URI']);
exit;
}

关于php - 多语言 .htaccess 重定向到子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10367732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com