douhui1957 2014-07-16 09:37
浏览 63

Symfony 2使用代理返回错误的url

I'm working on an Silex project and run into an issue with wrong url's when calling the site with a proxy.

Sitename without proxy: http://sitename.com/someFile.php

Sitename with proxy: https://sslsites.com/sitename.com/someFile.php

$_SERVER['HTTP_X_FORWARDED_HOST']: 'sslsites.com'

I set the Trusted Proxies in my index.php

Request::setTrustedProxies(array('sslsites.com'));

composer.json

"silex/silex": "1.0.*@dev",
"twig/twig": "~1.12",
"symfony/twig-bridge": "~2.2",
"symfony/validator": "~2.2",
"symfony/form": "~2.2",
"symfony/config": "~2.2",
"symfony/translation": "~2.2",
"symfony/locale": "~2.2",
"symfony/yaml": "~2.2",
"symfony/filesystem": "~2.2",
"symfony/finder": "~2.2",
"swiftmailer/swiftmailer": "~4.3",
"doctrine/dbal": "~2.3"

When running "url('category')" in a twig-Template, i'd expect:

https://sslsites.com/sitename.com/category

But I see instead

https://sslsites.com/category

I don't want a quick and dirty solution. Can anyone give me a hint?

  • 写回答

1条回答 默认 最新

  • dongsao8279 2014-07-16 10:20
    关注

    When using the component as part of the framework you can the router.request_context.base_url parameter, like so..

    parameters:
        router.request_context.base_url: my/path
    

    Which would lead me to believe that you would be able to use..

    if ($baseUrl = $app['request']->server->get('HTTP_X_FORWARDED_HOST')) {
        $app['request_context']->setBaseUrl($baseUrl);
    }
    

    I assume the best place to do this would be when you are creating the app but I may be wrong as I've only had a cursory glance at Silex.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!