Symfony 3 路由子域

Symfony 3 routing subdomains

我必须捆绑前端和后端。我希望子域 "admin.domain.com" 作为 "admin.domain.com/whateverpage" 工作并由后端捆绑控制器控制。所有其他子域应该像 "sub1.domain.com/{dynamicwhateverpage}" 或 "sub2.domain.com/{dynamicwhateverpage}" 一样工作,并由前端包控制器控制。

我让它与 "admin.domain.com/backend/whateverpage" 和 "sub1.domain.com/frontend/{dynamicwhateverpage}" 一起工作。 URL 中的后端和前端当然不应该对用户可见。有没有办法用 htaccess 重写?或者有没有更好的方法来实现这种重写?

Symfony 可以match routing based on host. This should also work when importing routes,虽然我没有测试过;

/**
 * @Route("/", name="project_page", host="{project}.example.com")
 */
public function projectPageAction($project) {
    // ...
}

只需确保您的 none 动态路线在所有捕获路线之前加载,或者确保项目路线无法匹配,例如。管理员。

Earlier Routes Always Win

Why would you ever care about requirements? If a request matches two routes, then the first route always wins.