简体   繁体   English

如何在不更改当前页面的情况下更改特定目录?

[英]How can I change a specific directory without changing the current page?

I want to create a directory switcher on my website (WordPress) like this:我想在我的网站(WordPress)上创建一个目录切换器,如下所示:

  • example.com/currentpage/ to example.com/fr/currentpage/ example.com/currentpage/example.com/fr/currentpage/

  • example.com to example.com/fr/ example.comexample.com/fr/

I tried this JavaScript code but it didn't work.我试过这个 JavaScript 代码,但它没有用。

<script>
  //Get current Pagename
  var currentPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);

  //Change href for link
  document.querySelector('a[href="/fr/"]').setAttribute('href', '/fr/'+ currentPage);
</script>

You seem to want to redirect based on language.您似乎想根据语言进行重定向。

For this, is easier to be done by Apache (if that is the server you are using), using the mod_rewrite module.为此, Apache (如果这是您正在使用的服务器)使用mod_rewrite模块更容易完成。

Please take a look at this other question on SO: Apache mod_rewrite accept language subdomain redirection请查看关于 SO 的其他问题: Apache mod_rewrite 接受语言子域重定向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM