dongzhijing8202 2015-01-13 10:14
浏览 52

symfony2语言受主机限制(从服务重定向?)

i'm making multi language site that can be run from different hosts.
some hosts can only have one language.

i'm having trouble figuring out how to redirect users from one language to another
for example:
if site.com only has de languge (site.com/de)
and someone tries to go directly to site.com/en i want redirect them to site.com/de straight away.

or how to restrict locale prefix based on host(should be dynamic)?

i think there is a way to do that from service listener but i dont know what to pass to it to be able to redirect from it.

  • 写回答

1条回答 默认 最新

  • 普通网友 2015-01-14 03:33
    关注

    First of all I think that this kind of limitations should be provided by httpd server configuration. For me this is a place where you should allow/disallow access based on remote host IP, and then redirect to allowed namespace of the site.

    Answering your question try to use JMSI18nRoutingBundle bundle, or similar. In this case you can overload Router/DefaultLocaleResolver.php class, replacing it in configuration (jms_i18n_routing.router.class).

    In your overloaded router add host based resolving to resolveLocale function by checking $request->getClientIp();. This way not only mainpage will be redirected to "proper" locale but also any link in your application.

    I think this is a cleanest way toy implement that.

    Good Luck!

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP