【问题标题】:generate seo friendly url for multi language system using php .htaccess使用 php .htaccess 为多语言系统生成 seo 友好的 url
【发布时间】:2015-03-17 07:13:14
【问题描述】:

我有这个使用 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/

对于文章ie:(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?!

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    我已经用这种方法解决了这个问题

    <?
    $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

    然后您可以包含来自确切语言文件的内容:

    include('.$page_code.'/content_'.$lang_code.'.php');
    

    内容的真实路径是:

    articles/content_de.php
    articles/content_en.php
    

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 2015-10-13
      • 2011-05-09
      • 2012-08-21
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      相关资源
      最近更新 更多