可以通过 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
Arheoloski-lokaliteti 自动转换为 Arheoloski-locality (通过API或其他东西)但是如何在其上应用htaccess重写?
答案 0 :(得分:0)
试试这个
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;
}
?>