为什么我的PHP没有指向我的西班牙语网站


Why isn't my PHP directing to my spanish site?

我的代码适用于我的所有网站,除了那些以"es"开头的网站。每当我尝试定向到这些网站时,它都会带我回到索引.html

这是我的索引.php代码:

<?php 
/*
*
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
 *
 */
include "app/config.php";
include "app/detect.php";
if ($page_name=='') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='index.html') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='es/index.html') {
    include $browser_t.'/es/index.html';
}
else
    {
        include $browser_t.'/404.html';
    }
?>

正在链接我的网站,以便您说出我的意思。在右上角有一个超链接,上面写着"Español",当你点击它时,它应该会带你到你当前所在页面的西班牙语版本。相反,它只是将您重新带到索引选项卡并更改子目录,但我翻译的页面没有出现。

在配置中.php我有以下内容:

<?php
/*
 * 
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
 *
 */
$current_page_uri = $_SERVER['REQUEST_URI'];
$part_url = explode("/", $current_page_uri);
$page_name = end($part_url);
$email_id = "support@elitecomps.com";
?>

我会在这里添加我的检测.php代码,但它是一个大文件,而不是我试图解决的问题,所以我只会链接它。

附言一切都适当地链接在一起,我已经三重检查了所有内容。我剩下的唯一嫌疑人是我的索引.php我不确定为什么。

$part_url = explode("/", $current_page_uri);
$page_name = end($part_url);

当URL为"es/index.html"时,该代码会将$page_name分配给"index.html",因为您只对上次/之后的内容感兴趣。

一种方法可能是使用 strrpos 检查字符串的末尾,例如

if(strrpos("es/index.html", $current_page_uri) !== FALSE)
    // Go to spanish site
else if(strrpos("index.html", $current_page_uri) !== FALSE)
    // Normal index page

您还可以检查$part_url中倒数第二个元素,并检查它是"es"还是任何其他语言代码。

如果我的逻辑正确,你应该在这里使用另一个条件

取代:

if ($page_name=='') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='index.html') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='es/index.html') {
    include $browser_t.'/es/index.html';
}
else
    {
        include $browser_t.'/404.html';
    }

if ($current_page_uri=='') {
    include $browser_t.'/index.html';
    }
elseif ($current_page_uri=='index.html') {
    include $browser_t.'/index.html';
    }
elseif ($current_page_uri=='es/index.html') {
    include $browser_t.'/es/index.html';
}
else
    {
        include $browser_t.'/404.html';
    }

我想你打算用$page_name作为检测器。 但是您尝试比较的值es/index.html实际上是您的 URI。