将查询添加到URL范围

时间:2016-04-12 11:17:37

标签: url translate

我想将查询 #googtrans(nl | en)添加到包含 / en /

的所有网址

http://example.nl/en/始终需要http://example.nl/en/#googtrans(nl|en)

example.nl/en/uncategorized/nieuws / 等子网址始终需要 example.nl/en/uncategorized/nieuws/#googtrans(nl | en)

也许有用:只要/ en /在网址中,我就有li class =" lang-en" as" lang-en active",但我不知道这是否有帮助。

目标是在加载英文网页时自动运行Google翻译。

通过 .htaccess 尝试添加:

RedirectMatch ^/en/(.*)$ example.nl/en/$1#googtrans(nl|en)

但是我的重定向错误太多了。还尝试了jquery但我的代码并没有在url本身上工作:

$(document).ready(function () { 
    $('li.lang-en.active') { 
        $(this).attr("href", $(this).attr("href") + "#googtrans(nl|en)”); 
    }) 
});

1 个答案:

答案 0 :(得分:0)

经过多次试验和试验错误(它无法通过.htaccess工作,我设法修复它:

<script>
if (document.location.pathname.indexOf("/en/") == 0) {
    window.location.hash = "#googtrans/nl/en";
}
</script>