首先我设置htaccess,删除php扩展,使用外部变量和语言标签缩短和美化URL。
文件.htaccess:
<IfModule mod_rewrite.c>
Options +MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ index.php [L]
RewriteRule ^$ index.php?hl=pt_BR [L]
RewriteRule ^$ index.php?hl=en [L]
RewriteRule ^galeria$ album.php [L]
RewriteRule ^galeria$ album.php?hl=pt_BR [L]
RewriteRule ^photos$ album.php?hl=en [L]
# Return 404 if original request is .php
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
# RewriteRule .* - [L,R=404]
</IfModule>
我的网站有两种语言。
PHP中的两种语言:
en.php:
define('_album', "Photos Gallery");
define('_html_lingua', "en");
define('_url_album', "photos");
pt.php:
define('_album', "Galeria");
define('_html_lingua', "pt_BR");
define('_url_album', "galeria");
现在,我将_url_album添加到了一个锚点:
<li><a class="waves-effect" href="<?php echo _url_album; ?>?hl=<?php echo _html_lingua ?>"><?php echo _album; ?></a></li>
输出如下:
如果你切换到英语:
<li><a class="waves-effect" href="photos?hl=en">Photos Gallery</a></li>
如果您切换到葡萄牙语:
<li><a class="waves-effect" href="galeria?hl=pt_BR">Galeria</a></li>
然后在语言选择器中:
<li><a class="waves-effect" href="<?php if (basename($_SERVER['PHP_SELF']) == "album.php?hl=en") { echo _url_album; } ?>?hl=en" name="en"><img alt=""src="imagens/bandeiras/en.svg"> English</a></li>
<li><a class="waves-effect" href="<?php if (basename($_SERVER['PHP_SELF']) == "album.php?hl=pt_BR") { echo _url_album; } ?>?hl=pt_BR" name="pt_BR"><img alt="" src="imagens/bandeiras/pt-br.svg"> Português Brasileiro</a></li>
应该是这样的:
<li><a class="waves-effect" href="photos?hl=en" name="en"><img alt=""src="imagens/bandeiras/en.svg"> English</a></li>
<li><a class="waves-effect" href="galeria?hl=pt_BR" name="pt_BR"><img alt="" src="imagens/bandeiras/pt-br.svg"> Português Brasileiro</a></li>
但是在专辑页面上,用英语,在语言选择器中,如果你悬停葡萄牙语而不点击,它会显示为&#34; photos?hl=pt_BR
&#34;而不是&#34; galeria?hl=pt_BR
&#34;。在葡萄牙语中,如果您将鼠标悬停在英语上,则显示为&#34; galeria?php=en
&#34;。我发现它很难看。
我想这样做:在葡萄牙语中,如果你徘徊英语,我希望它显示为&#34; photos?hl=en
&#34;在语言选择器。所以!