url 重写以实现国际化
我正在我的网站中实现国际化,我希望用户能够输入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本原理
是:将语言代码(前两个字符)作为第一个正则表达式结果,然后将 URL 的其余部分(直到
$
)作为第二个正则表达式结果。最后,使用 URL 的其余部分,并附加&lang=$1
部分($1
和$2
表示第一个和第二个匹配项括号内的部分)。It would be something like:
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).