htaccess多语言不起作用

时间:2017-03-05 22:41:13

标签: php .htaccess multilingual

我使用多种语言。但是,我有一个问题。我的代码不起作用。 默认语言始终有效。

例如:
www.mysite.com/tr/hakkimizda
www.mysite.com/en/about-us

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^dil=([a-z]{2})(?:&|$) [NC]
RewriteRule !^[a-z]{2}/ /%1/%{REQUEST_URI}? [L,NC,R=301]

# default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^dil=.+(&|$) [NC]
RewriteRule !^tr/ /tr/%{REQUEST_URI} [L,NC,R=301]


**language.php**
$dil=$_GET["dil"];

if(file_exists("dil/".$dil.".php")){
    $_SESSION["dil"]=$dil;
    header("Location:/");
}else{
    header("Location:tr");
}

链接类型
language.php?dil = tr(location index.php)
language.php?dil = en(location index.php)

我想成为 www.mysite.com/tr/hakkimizda
www.mysite.com/en/about-us

1 个答案:

答案 0 :(得分:0)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^dil=([a-z]{2})(?:&|$) [NC]
RewriteRule !^[a-z]{2}/ /%1/%{REQUEST_URI}? [L,NC,R=301]

# missing rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/ language.php?dil=$1 [L,NC]

# default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^dil=.+(&|$) [NC]
RewriteRule !^tr/ /tr/%{REQUEST_URI} [L,NC,R=301]