所以,我正在建立一个网站,我将它与index.php文件中的包含在一起。 问题是网站打开并完美显示第一页,但没有一种语言链接工作! 这是我的代码:
索引文件:
<?php
$languages = array("eng","lat");
$sections = array("home");
$sectionTitles = array("eng" =>array(
"WHERE CAN YOU FIND US?",
"WHO ARE WE?",
"CONTACTS",
),
"lat"=>array(
"KUR MŪS ATRAST?",
"PAR MUMS",
"KONTAKTI",
));
$lang = "lat";
$section = "home";
$content = explode("/", $_SERVER['REQUEST_URI']);
if (!empty($content[1]) && (in_array($content[1], $languages))) { $lang = $content[1];}
if (!empty($content[2]) && (in_array($content[2], $sections))) { $section = $content[2];}
$sectionTitles = $sectionTitles[$lang];
include ("header.php");
include ("$lang/$section.php");
include ("footer.php");
?>
.htaccess文件:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g|pdf|eot|svg|ttf|woff|ico)$
RewriteRule (.*)$ /index.php [L]
标题文件中的链接:
<a href="/eng/<?=$section?>">eng</a>
提前谢谢!
答案 0 :(得分:2)
将htaccess文件更改为
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g|pdf|eot|svg|ttf|woff|ico)$
RewriteRule (.*)$ /index.php?_url=$1 [L]
然后你可以使用
$content = explode("/", $_GET['_url']);