是否可以通过htaccess和php翻译URL slug?例如:
http://www.example.com/sr/Arheoloski-lokaliteti.html --> index.php?lang=sr
点击带有EN标志的图标,然后重定向到这里:
http://www.example.com/en/Arheoloski-locality.html --> index.php?lang=en
Arheloski-localiteti自动翻译为ARheloski-locality(通过API或其他方式),但如何对其应用htaccess重写?
尝试这个
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ([^'/.]*).*'/(.*).html$ index.php?lang=$1&page=$2 [NC,L]
然后是index.php
<?php
$language = isset($_GET['lang']) ? $_GET['lang'] : "default";
$page = isset($_GET['page']) ? $_GET['page'] : "default";
switch($language){
case "en":
//logic to pull appropriate content based on $page value
break;
case "sr":
//logic to pull appropriate content based on $page value
break;
default:
//logic to pull appropriate content based on $page value
break;
}
?>