PHP在.htacces中添加新规则默认语言

时间:2015-07-09 13:18:34

标签: php .htaccess mod-rewrite

我的网站中有两种语言(en& fr)。我使用.htaccess重写了我的网址:

RewriteEngine On
RewriteBase /pms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(fr|en)/([A-Za-z0-9-]+)/([0-9]+)/([A-Za-z0-9-]+)/?.html$ article.php?page=$2&id=$3&title=$4&lang=$1 [NC,L,QSA] 

这对我的网址都适用于这两种语言:

website.com/en/page/10/title.html   <- english language
website.com/fr/page/10/title.html   <- french language

我的defualt语言为en,我需要从网址中删除默认语言,并在网址中仅显示第二种语言,如下所示:

website.com/page/10/title.html  <- english language
website.com/fr/page/10/title.html  <- french language

如何为此创建规则?

1 个答案:

答案 0 :(得分:0)

尝试:

RewriteEngine On
RewriteBase /pms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(fr)/([A-Za-z0-9-]+)/([0-9]+)/([A-Za-z0-9-]+)/?.html$ article.php?page=$2&id=$3&title=$4&lang=$1 [NC,L,QSA] 

#Rule for en
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([A-Za-z0-9-]+)/?.html$ article.php?page=$1&id=$2&title=$3&lang=en [NC,L,QSA]