我知道可以通过主机过滤路线,如下所示:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: backend.domain.com
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
是否可以更改此配置以匹配多个域?例如:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: backend.domain.com|dev.backend.domain.com
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
我试图避免为每个页面设置2条路线。
答案 0 :(得分:4)
您可以在主机名中尝试占位符(即Symfony Documentation)
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{mydomaines}"
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
requirements:
mydomaines: backend.domain.com|dev.backend.domain.com
答案 1 :(得分:3)
如果您阅读Symfony documentation,则表示您需要使用占位符。对于您的代码,它将是:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{subdomain}.domain.com"
defaults:
_controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index
subdomain: backend
requirements:
subdomain: backend|dev.backend
我希望它能帮到你!
编辑:
如果您希望默认子域名是当前子域名,可以使用如下参数:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{subdomain}.domain.com"
defaults:
_controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index
subdomain: "%subdomain%"
requirements:
subdomain: backend|dev.backend
然后,您将能够使用以下代码行在Event listener中定义此参数:
$container->setParameter("subdomain", $your_subdomain);
P-S:不要忘记将服务容器添加到监听器的依赖项