我有这个使用 php 的多语言系统的网址:
http://mydomain/ <-- default language english (en)
http://mydomain/index.php?lang=de
http://mydomain/index.php?lang=fr
http://mydomain/index.php?lang=tr
现在,对于另一个页面,我有这个网址:
http://mydomain/article.php?id=xx <-- show article details
http://mydomain/article.php?list=all <-- show article archive
http://mydomain/gallery.php?id=xx
http://mydomain/faq.php?id=xx
http://mydomain/faq.php?list=all
http://mydomain/contact.php
现在,我需要使用 php 和 htaccess 创建 seo 友好的 url,如下所示:
对于索引:
http://mydomain/ <-- for default
http://mydomain/de/
http://mydomain/fr/
对于文章即:(domain/lang/id/title.html
)
http://mydomain/de/articles/22/test.html
对于页面:
http://mydomain/de/contact.html
对于存档:
http://mydomain/de/articles/listall.html
在HTaccess中,我为文章编写了以下代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([0-9]+)/([A-Za-z0-9-]+)/?.html$ articles.php?id=$1
但这适用于一种语言而不是多种语言。 如何为多语言系统创建 SEO 友好的 URL?!
我已经用这种方式解决了这个问题
<?
$request_uri=explode('/',$_SERVER['REQUEST_URI']);;
$lang_code=$request_uri[1];
$page_code=$request_uri[2];
?>
对于 de/articles/listall.html,您将获得$lang_code=de和页面代码:$page_code=articles
然后,您可以包含确切的 lang 文件中的内容:
include('.$page_code.'/content_'.$lang_code.'.php');
内容的真正路径是:
articles/content_de.php
articles/content_en.php