url 重写以实现国际化

发布于 2024-10-01 08:52:55 字数 384 浏览 0 评论 0原文

我正在我的网站中实现国际化,我希望用户能够输入 url,例如:

http://www.mysite.com/en/showprofile.php?id=1000
http://www.mysite.com/de/showprofile.php?id=1000

并将其重写为

http://www.mysite.com/showprofile.php?id=1000&lang=en
http://www.mysite.com/showprofile.php?id=1000&lang=de

据我所知,这可以通过我的 .htaccess 文件中的 url 重写来完成 我不太确定确切的内容句法。提前致谢。

i'm implementation internationalization in my site and i would like users to be able to enter urls such as :

http://www.mysite.com/en/showprofile.php?id=1000
http://www.mysite.com/de/showprofile.php?id=1000

and have this rewritten to

http://www.mysite.com/showprofile.php?id=1000&lang=en
http://www.mysite.com/showprofile.php?id=1000&lang=de

From what i understand this can be done with url rewriting in my .htaccess file am not too sure about the exact syntax. thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情洁癖 2024-10-08 08:52:55

基本原理

RewriteEngine on
RewriteRule (..)/(.*)$ $2&lang=$1

是:将语言代码(前两个字符)作为第一个正则表达式结果,然后将 URL 的其余部分(直到 $)作为第二个正则表达式结果。最后,使用 URL 的其余部分,并附加 &lang=$1 部分($1$2 表示第一个和第二个匹配项括号内的部分)。

It would be something like:

RewriteEngine on
RewriteRule (..)/(.*)$ $2&lang=$1

The rationale is: Take the language code (the two first characters) as a first regex result, then the rest of the URL (till the $) as the second regex result. Finally, use the rest of the URL, and append the &lang=$1 part ($1 and $2 denote the first and second matches of parts within parentheses).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文