简体   繁体   English

在Symfony 2中,如何将URL重定向到Symfony捆绑包页面?

[英]In Symfony 2, how to redirect a URL to a Symfony bundle page?

I was trying to make a Symfony 2 page when accessed through a browser (ex. example.com) it will redirect to the index page of a bundle. 通过浏览器(例如example.com)访问时,我试图制作一个Symfony 2页面,它将重定向到捆绑软件的索引页面。

There shouldn't be a example.com/web or anything at all, how can I achieve this? 根本不应该有example.com/web或任何内容,我该如何实现?

You can redirect() to generate an HTTP redirect. 您可以redirect()生成HTTP重定向。

return $this->redirect($this->generateUrl('bundle_index')); // 302 Moved

Or you render immediately without a redirect using forward() , so the URL wouldn't change. 或者,您可以使用forward()立即进行渲染而无需重定向,因此URL不会更改。

return $this->forward($this->generateUrl('bundle_index'));

The other option is to explicitly connect the home page path, to a controller. 另一个选择是将主页路径明确连接到控制器。

# routing.yml
_default:
    resource: "@YourDefaultBundle/Controller/"
    type:     annotation
    prefix:   /

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

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